diff options
author | Pascal Rapicault | 2010-12-06 22:10:52 +0000 |
---|---|---|
committer | Pascal Rapicault | 2010-12-06 22:10:52 +0000 |
commit | fbb4f5902cade92cc1689e73209c60a6413a5ef7 (patch) | |
tree | ace0fb107bafe980fc14fd7f3429e5c9aac2d795 /org.eclipse.m2e.jdt | |
parent | a9c878c2624b33d8c74062717bf75302f0ae1fa7 (diff) | |
download | m2e-core-fbb4f5902cade92cc1689e73209c60a6413a5ef7.tar.gz m2e-core-fbb4f5902cade92cc1689e73209c60a6413a5ef7.tar.xz m2e-core-fbb4f5902cade92cc1689e73209c60a6413a5ef7.zip |
Initial commit at Eclipse
Diffstat (limited to 'org.eclipse.m2e.jdt')
50 files changed, 5363 insertions, 0 deletions
diff --git a/org.eclipse.m2e.jdt/.classpath b/org.eclipse.m2e.jdt/.classpath new file mode 100644 index 00000000..798048dd --- /dev/null +++ b/org.eclipse.m2e.jdt/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src/"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/org.eclipse.m2e.jdt/.gitignore b/org.eclipse.m2e.jdt/.gitignore new file mode 100644 index 00000000..4dc00917 --- /dev/null +++ b/org.eclipse.m2e.jdt/.gitignore @@ -0,0 +1,2 @@ +/target +/bin diff --git a/org.eclipse.m2e.jdt/.options b/org.eclipse.m2e.jdt/.options new file mode 100644 index 00000000..df7eb573 --- /dev/null +++ b/org.eclipse.m2e.jdt/.options @@ -0,0 +1,11 @@ +# Debugging options for the org.eclipse.m2e.jdt plugin. + +# Turn on debugging for the org.eclipse.m2e.jdt plugin. +org.eclipse.m2e.jdt/debug=false + +# Plugin initialization +org.eclipse.m2e.jdt/debug/initialization=false + +# Maven compilation participant +org.eclipse.m2e.jdt/debug/compilationParticipant=false + diff --git a/org.eclipse.m2e.jdt/.project b/org.eclipse.m2e.jdt/.project new file mode 100644 index 00000000..e3aeb613 --- /dev/null +++ b/org.eclipse.m2e.jdt/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.m2e.jdt</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.maven.ide.eclipse.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.maven.ide.eclipse.maven2Nature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..6d183aba --- /dev/null +++ b/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,360 @@ +#Thu Feb 04 10:56:11 EST 2010 +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.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +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=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.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.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.missingSerialVersion=warning +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.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=error +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=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +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_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 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +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_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_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.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 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=1 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=2 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=true +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=true +org.eclipse.jdt.core.formatter.comment.format_block_comments=false +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=false +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +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.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.format_guardian_clause_on_one_line=false +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 +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true +org.eclipse.jdt.core.formatter.indentation.size=2 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=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_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 +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +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_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_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 +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +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_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 +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +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_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 +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +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_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 +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +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.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 +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=120 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=true +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=true +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +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_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.incompatibleJDKLevel=ignore +org.eclipse.jdt.core.incompleteClasspath=error diff --git a/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000..1475a796 --- /dev/null +++ b/org.eclipse.m2e.jdt/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,14 @@ +#Tue Nov 30 18:52:17 EST 2010 +eclipse.preferences.version=1 +formatter_profile=_m2 plugin +formatter_settings_version=11 +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;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 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\nMavenLogger.log(${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\nMavenLogger.log(${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> diff --git a/org.eclipse.m2e.jdt/.settings/org.eclipse.mylyn.tasks.ui.prefs b/org.eclipse.m2e.jdt/.settings/org.eclipse.mylyn.tasks.ui.prefs new file mode 100644 index 00000000..c22247a8 --- /dev/null +++ b/org.eclipse.m2e.jdt/.settings/org.eclipse.mylyn.tasks.ui.prefs @@ -0,0 +1,4 @@ +#Fri Aug 01 10:04:25 EDT 2008 +eclipse.preferences.version=1 +project.repository.kind=jira +project.repository.url=http\://jira.codehaus.org diff --git a/org.eclipse.m2e.jdt/.settings/org.eclipse.mylyn.team.ui.prefs b/org.eclipse.m2e.jdt/.settings/org.eclipse.mylyn.team.ui.prefs new file mode 100644 index 00000000..2b36dd4a --- /dev/null +++ b/org.eclipse.m2e.jdt/.settings/org.eclipse.mylyn.team.ui.prefs @@ -0,0 +1,3 @@ +#Fri Aug 01 10:04:25 EDT 2008 +commit.comment.template=${task.key}\: ${task.description} +eclipse.preferences.version=1 diff --git a/org.eclipse.m2e.jdt/.settings/org.eclipse.pde.core.prefs b/org.eclipse.m2e.jdt/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 00000000..da324b13 --- /dev/null +++ b/org.eclipse.m2e.jdt/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +#Fri Oct 26 19:41:18 EDT 2007 +eclipse.preferences.version=1 +resolve.requirebundle=false diff --git a/org.eclipse.m2e.jdt/.settings/org.eclipse.pde.prefs b/org.eclipse.m2e.jdt/.settings/org.eclipse.pde.prefs new file mode 100644 index 00000000..94ae750a --- /dev/null +++ b/org.eclipse.m2e.jdt/.settings/org.eclipse.pde.prefs @@ -0,0 +1,23 @@ +#Sat Jul 05 10:00:23 EDT 2008 +compilers.f.unresolved-features=1 +compilers.f.unresolved-plugins=1 +compilers.incompatible-environment=1 +compilers.p.build=1 +compilers.p.deprecated=2 +compilers.p.discouraged-class=1 +compilers.p.internal=1 +compilers.p.missing-packages=2 +compilers.p.no-required-att=0 +compilers.p.not-externalized-att=2 +compilers.p.unknown-attribute=1 +compilers.p.unknown-class=1 +compilers.p.unknown-element=1 +compilers.p.unknown-identifier=1 +compilers.p.unknown-resource=1 +compilers.p.unresolved-ex-points=0 +compilers.p.unresolved-import=0 +compilers.s.create-docs=false +compilers.s.doc-folder=doc +compilers.s.open-tags=1 +compilers.use-project=true +eclipse.preferences.version=1 diff --git a/org.eclipse.m2e.jdt/.settings/org.maven.ide.eclipse.prefs b/org.eclipse.m2e.jdt/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 00000000..0029eebb --- /dev/null +++ b/org.eclipse.m2e.jdt/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Tue Nov 16 11:32:19 EST 2010 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF b/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF new file mode 100644 index 00000000..c3c66e14 --- /dev/null +++ b/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.m2e.jdt;singleton:=true +Bundle-Version: 0.13.0.qualifier +Bundle-Localization: plugin +Export-Package: org.eclipse.m2e.jdt, + org.eclipse.m2e.jdt.internal;x-friends:="org.eclipse.m2e.tests", + org.eclipse.m2e.jdt.internal.launch;x-friends:="org.eclipse.m2e.tests" +Require-Bundle: org.eclipse.core.resources, + org.eclipse.core.runtime, + org.eclipse.jface, + org.eclipse.jface.text, + org.eclipse.debug.core, + org.eclipse.jdt.core, + org.eclipse.jdt.launching, + org.eclipse.jdt.ui, + org.eclipse.ui.workbench, + org.eclipse.ui.ide, + org.eclipse.ltk.core.refactoring, + org.eclipse.search, + org.eclipse.m2e.maven.runtime;bundle-version="[0.13.0,0.14.0)", + org.eclipse.m2e.model.edit;bundle-version="[0.13.0,0.14.0)", + org.eclipse.m2e.core;bundle-version="[0.13.0,0.14.0)", + org.eclipse.ui.console +Eclipse-LazyStart: true +Bundle-Activator: org.eclipse.m2e.jdt.MavenJdtPlugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5, + JavaSE-1.6 +Bundle-Vendor: %Bundle-Vendor diff --git a/org.eclipse.m2e.jdt/about.html b/org.eclipse.m2e.jdt/about.html new file mode 100644 index 00000000..70e4b67c --- /dev/null +++ b/org.eclipse.m2e.jdt/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>October 29, 2010</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html> diff --git a/org.eclipse.m2e.jdt/build.properties b/org.eclipse.m2e.jdt/build.properties new file mode 100644 index 00000000..14da2312 --- /dev/null +++ b/org.eclipse.m2e.jdt/build.properties @@ -0,0 +1,19 @@ +# +# Copyright (c) 2008-2010 Sonatype, Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Sonatype, Inc. - initial API and implementation +# + +bin.includes = META-INF/,\ + plugin.xml,\ + plugin.properties,\ + .,\ + about.html +jars.compile.order = . +source.. = src/ +output.. = target/classes/ diff --git a/org.eclipse.m2e.jdt/icons/javadoc.gif b/org.eclipse.m2e.jdt/icons/javadoc.gif Binary files differnew file mode 100644 index 00000000..c43c5d51 --- /dev/null +++ b/org.eclipse.m2e.jdt/icons/javadoc.gif diff --git a/org.eclipse.m2e.jdt/icons/m2.gif b/org.eclipse.m2e.jdt/icons/m2.gif Binary files differnew file mode 100644 index 00000000..4b0c0589 --- /dev/null +++ b/org.eclipse.m2e.jdt/icons/m2.gif diff --git a/org.eclipse.m2e.jdt/plugin.properties b/org.eclipse.m2e.jdt/plugin.properties new file mode 100644 index 00000000..52745875 --- /dev/null +++ b/org.eclipse.m2e.jdt/plugin.properties @@ -0,0 +1,26 @@ +# +# Copyright (c) 2007, 2008 Sonatype, Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + +m2.classpath-container.name=Maven Classpath Container +m2.classpath-container.page.name=Maven Classpath Container Page +m2.classpath-container.page.dependencies.name=Maven Managed Dependencies + +m2.popup.menu.label=Maven + + +Bundle-Vendor = Sonatype, Inc. +Bundle-Name = Maven Integration for Eclipse JDT +configurator.jdt.name = JDT +filter.description = Filters module folders from the Maven projects +filter.name = Maven modules filter +action.label = label +action.javadoc.label = Open JavaDoc +action.javadoc2.label = Open JavaDoc +action.javadoc3.label = Open JavaDoc +action.javadoc4.label = Open JavaDoc +lifecycleMapping.jar.name = Jar Lifecycle Mapping
\ No newline at end of file diff --git a/org.eclipse.m2e.jdt/plugin.xml b/org.eclipse.m2e.jdt/plugin.xml new file mode 100644 index 00000000..0299bbbc --- /dev/null +++ b/org.eclipse.m2e.jdt/plugin.xml @@ -0,0 +1,196 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2007, 2008 Sonatype, Inc. + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/epl-v10.html +--> +<?eclipse version="3.2"?> +<plugin> + <extension + point="org.eclipse.m2e.core.lifecycleMappings"> + <lifecycleMapping + class="org.eclipse.m2e.jdt.internal.JarLifecycleMapping" + id="jar" + name="%lifecycleMapping.jar.name" + packaging-type="jar"> + <mojo + artifactId="maven-compiler-plugin" + goals="compile,testCompile" + groupId="org.apache.maven.plugins" + versionRange="[2.0,)"> + <configurator + id="org.eclipse.m2e.jdt.javaConfigurator"> + </configurator> + </mojo> + <mojo + artifactId="maven-resources-plugin" + goals="resources,testResources" + groupId="org.apache.maven.plugins" + versionRange="[2.4,)"> + <configurator + id="org.eclipse.m2e.core.project.configurator.MavenResourcesProjectConfigurator"> + </configurator> + </mojo> + </lifecycleMapping> + </extension> + + <extension point="org.eclipse.jdt.core.classpathContainerInitializer" + id="maven2ClasspathContainer" + name="%m2.classpath-container.name"> + <classpathContainerInitializer + id="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" + class="org.eclipse.m2e.jdt.internal.MavenClasspathContainerInitializer"/> + </extension> + + <extension point="org.eclipse.jdt.ui.classpathContainerPage" + id="maven2ClasspathContainerPage" + name="%m2.classpath-container.page.name"> + <classpathContainerPage + id="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" + name="%m2.classpath-container.page.dependencies.name" + class="org.eclipse.m2e.jdt.internal.ui.MavenClasspathContainerPage"/> + </extension> + + <extension point="org.eclipse.jdt.launching.classpathProviders"> + <classpathProvider + id="org.eclipse.m2e.launchconfig.classpathProvider" + class="org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider"/> + <classpathProvider + id="org.eclipse.m2e.launchconfig.sourcepathProvider" + class="org.eclipse.m2e.jdt.internal.launch.MavenSourcePathProvider"/> + </extension> + + <extension point="org.eclipse.m2e.core.projectConfigurators"> + <configurator + class="org.eclipse.m2e.jdt.internal.JavaProjectConfigurator" + id="org.eclipse.m2e.jdt.javaConfigurator" + name="%configurator.jdt.name"> + </configurator> + </extension> + + <extension point="org.eclipse.jdt.core.classpathVariableInitializer"> + <classpathVariableInitializer variable="M2_REPO" readOnly="true" + class="org.eclipse.m2e.jdt.internal.MavenClasspathVariableInitializer"/> + </extension> + + <extension point="org.eclipse.core.runtime.adapters"> + <factory adaptableType="org.eclipse.jdt.core.IPackageFragmentRoot" + class="org.eclipse.m2e.jdt.internal.JavaElementsAdapterFactory"> + <adapter type="org.eclipse.m2e.core.embedder.ArtifactKey"/> + <adapter type="org.eclipse.core.runtime.IPath"/> + <adapter type="org.eclipse.m2e.core.project.IMavenProjectFacade"/> + </factory> + <factory adaptableType="org.eclipse.jdt.core.IJavaProject" + class="org.eclipse.m2e.jdt.internal.JavaElementsAdapterFactory"> + <adapter type="org.eclipse.m2e.core.embedder.ArtifactKey"/> + <adapter type="org.eclipse.core.runtime.IPath"/> + <adapter type="org.eclipse.m2e.core.project.IMavenProjectFacade"/> + </factory> + <factory adaptableType="org.eclipse.jdt.internal.ui.packageview.ClassPathContainer$RequiredProjectWrapper" + class="org.eclipse.m2e.jdt.internal.JavaElementsAdapterFactory"> + <adapter type="org.eclipse.m2e.core.embedder.ArtifactKey"/> + <adapter type="org.eclipse.core.runtime.IPath"/> + <adapter type="org.eclipse.m2e.core.project.IMavenProjectFacade"/> + </factory> + </extension> + + <extension point="org.eclipse.jdt.core.compilationParticipant"> + <compilationParticipant + id="org.eclipse.m2e.compilationParticipant" + class="org.eclipse.m2e.jdt.internal.JDTCompilationParticipant" + createsProblems="false" + modifiesEnvironment="false"/> + </extension> + + <extension point="org.eclipse.ui.popupMenus"> + <objectContribution id="org.eclipse.m2e.classpathMenu" + objectClass="org.eclipse.jdt.core.IPackageFragmentRoot" + adaptable="true"> + <action id="org.eclipse.m2e.classpathMenu.action" + class="org.eclipse.m2e.core.actions.MavenMenuAction" + label="%m2.popup.menu.label" + style="pulldown" + menubarPath="additions" + enablesFor="1" + icon="icons/m2.gif"/> + </objectContribution> + <objectContribution id="org.eclipse.m2e.classpathMenuWrapper" + objectClass="org.eclipse.jdt.internal.ui.packageview.ClassPathContainer$RequiredProjectWrapper" + adaptable="true"> + <action id="org.eclipse.m2e.classpathMenu.action" + class="org.eclipse.m2e.core.actions.MavenMenuAction" + label="%m2.popup.menu.label" + style="pulldown" + menubarPath="additions" + enablesFor="1" + icon="icons/m2.gif"/> + </objectContribution> + </extension> + + <extension point="org.eclipse.m2e.core.m2menu"> + <factory class="org.eclipse.m2e.jdt.internal.ui.MavenJdtMenuCreator"/> + </extension> + + <extension point="org.eclipse.jdt.ui.javaElementFilters"> + <filter id="org.eclipse.m2e.MavenModuleFilter" + targetId="org.eclipse.jdt.ui.PackageExplorer" + class="org.eclipse.m2e.ui.internal.filter.MavenModuleFilter" + description="%filter.description" + name="%filter.name" + enabled="false"/> + </extension> + + <extension point="org.eclipse.ui.editorActions"> + <editorContribution id="org.eclipse.m2e.jdt.downloadSourcesContribution" + targetID="org.eclipse.jdt.ui.ClassFileEditor"> + <action id="org.eclipse.m2e.jdt.downloadSourcesAction" + class="org.eclipse.m2e.jdt.DownloadSourcesActionDelegate" + label="%action.label" style="push"/> + </editorContribution> + </extension> + + <extension point="org.eclipse.ui.popupMenus"> + <objectContribution id="org.eclipse.m2e.openJavaDocArtifact" + objectClass="org.apache.maven.artifact.Artifact" + adaptable="false"> + <action id="org.eclipse.m2e.ui.openJavaDocArtifact" + class="org.eclipse.m2e.jdt.internal.actions.OpenJavaDocAction" + label="%action.javadoc.label" + enablesFor="1" icon="icons/javadoc.gif"/> + </objectContribution> + <objectContribution id="org.eclipse.m2e.openJavaDocDependencyNode" + objectClass="org.apache.maven.shared.dependency.tree.DependencyNode" + adaptable="false"> + <action id="org.eclipse.m2e.ui.openJavaDocDependencyNode" + class="org.eclipse.m2e.jdt.internal.actions.OpenJavaDocAction" + label="%action.javadoc2.label" + enablesFor="1" icon="icons/javadoc.gif"/> + </objectContribution> + <objectContribution id="org.eclipse.m2e.openJavaDocDependencyNodeAether" + objectClass="org.sonatype.aether.graph.DependencyNode" + adaptable="false"> + <action id="org.eclipse.m2e.ui.openJavaDocDependencyNode" + class="org.eclipse.m2e.jdt.internal.actions.OpenJavaDocAction" + label="%action.javadoc3.label" + enablesFor="1" icon="icons/javadoc.gif"/> + </objectContribution> + <objectContribution id="org.eclipse.m2e.openJavaDocDependency" + objectClass="org.eclipse.m2e.model.edit.pom.Dependency" + adaptable="false"> + <action id="org.eclipse.m2e.ui.openJavaDocDependency" + class="org.eclipse.m2e.jdt.internal.actions.OpenJavaDocAction" + label="%action.javadoc4.label" + enablesFor="1"/> + </objectContribution> + </extension> + <extension + point="org.eclipse.m2e.core.lifecycleMappingPropertyPage"> + <lifecycleMappingPropertyPage + class="org.eclipse.m2e.core.ui.internal.preferences.CustomizableLifecycleMappingPropertyPage" + lifecycleMappingId="jar"> + </lifecycleMappingPropertyPage> + </extension> + +</plugin> diff --git a/org.eclipse.m2e.jdt/pom.xml b/org.eclipse.m2e.jdt/pom.xml new file mode 100644 index 00000000..3f5901c8 --- /dev/null +++ b/org.eclipse.m2e.jdt/pom.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2008 Sonatype, Inc. + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/epl-v10.html +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.m2e</groupId> + <artifactId>org.eclipse.m2e.parent</artifactId> + <version>0.13.0-SNAPSHOT</version> + <relativePath>../org.eclipse.m2e.parent</relativePath> + </parent> + + <artifactId>org.eclipse.m2e.jdt</artifactId> + <packaging>eclipse-plugin</packaging> + + <name>Maven Integration for Eclipse JDT</name> + +</project> diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/BuildPathManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/BuildPathManager.java new file mode 100644 index 00000000..d6ef5063 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/BuildPathManager.java @@ -0,0 +1,923 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IElementChangedListener; +import org.eclipse.jdt.core.IJavaElementDelta; +import org.eclipse.jdt.core.IJavaModel; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.core.DeltaProcessingState; +import org.eclipse.jdt.internal.core.JavaElementDelta; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.project.MavenProject; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenConsole; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.embedder.IMavenConfiguration; +import org.eclipse.m2e.core.index.IndexManager; +import org.eclipse.m2e.core.index.IndexedArtifactFile; +import org.eclipse.m2e.core.project.IMavenProjectChangedListener; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.core.project.configurator.ILifecycleMapping; +import org.eclipse.m2e.jdt.internal.ClasspathDescriptor; +import org.eclipse.m2e.jdt.internal.DefaultClasspathManagerDelegate; +import org.eclipse.m2e.jdt.internal.MavenClasspathContainer; +import org.eclipse.m2e.jdt.internal.MavenClasspathContainerSaveHelper; +import org.eclipse.m2e.jdt.internal.Messages; + +/** + * This class is responsible for mapping Maven classpath to JDT and back. + * + * @deprecated this classes is internal implementation and should be replaced with IClasspathManager before 1.0 + */ +@SuppressWarnings("restriction") +public class BuildPathManager implements IMavenProjectChangedListener, IResourceChangeListener { + + // container settings + public static final String CONTAINER_ID = "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"; //$NON-NLS-1$ + + // entry attributes + public static final String GROUP_ID_ATTRIBUTE = "maven.groupId"; //$NON-NLS-1$ + + public static final String ARTIFACT_ID_ATTRIBUTE = "maven.artifactId"; //$NON-NLS-1$ + + public static final String VERSION_ATTRIBUTE = "maven.version"; //$NON-NLS-1$ + + public static final String CLASSIFIER_ATTRIBUTE = "maven.classifier"; //$NON-NLS-1$ + + public static final String SCOPE_ATTRIBUTE = "maven.scope"; //$NON-NLS-1$ + + // local repository variable + public static final String M2_REPO = "M2_REPO"; //$NON-NLS-1$ + + private static final String PROPERTY_SRC_ROOT = ".srcRoot"; //$NON-NLS-1$ + + private static final String PROPERTY_SRC_PATH = ".srcPath"; //$NON-NLS-1$ + + private static final String PROPERTY_JAVADOC_URL = ".javadoc"; //$NON-NLS-1$ + + static final String CLASSIFIER_SOURCES = "sources"; //$NON-NLS-1$ + + static final String CLASSIFIER_JAVADOC = "javadoc"; //$NON-NLS-1$ + + static final String CLASSIFIER_TESTS = "tests"; //$NON-NLS-1$ + + static final String CLASSIFIER_TESTSOURCES = "test-sources"; //$NON-NLS-1$ + + public static final int CLASSPATH_TEST = 0; + + public static final int CLASSPATH_RUNTIME = 1; + + // test is the widest possible scope, and this is what we need by default + public static final int CLASSPATH_DEFAULT = CLASSPATH_TEST; + + public static final ArtifactFilter SCOPE_FILTER_RUNTIME = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME); + + public static final ArtifactFilter SCOPE_FILTER_TEST = new ScopeArtifactFilter(Artifact.SCOPE_TEST); + + final MavenConsole console; + + final MavenProjectManager projectManager; + + final IMavenConfiguration mavenConfiguration; + + final IndexManager indexManager; + + final BundleContext bundleContext; + + final IMaven maven; + + final File stateLocationDir; + + private String jdtVersion; + + private final DownloadSourcesJob downloadSourcesJob; + + private final DefaultClasspathManagerDelegate defaultDelegate; + + public BuildPathManager(MavenConsole console, MavenProjectManager projectManager, IndexManager indexManager, + BundleContext bundleContext, File stateLocationDir) { + this.console = console; + this.projectManager = projectManager; + this.indexManager = indexManager; + this.mavenConfiguration = MavenPlugin.getDefault().getMavenConfiguration(); + this.bundleContext = bundleContext; + this.stateLocationDir = stateLocationDir; + this.maven = MavenPlugin.getDefault().getMaven(); + this.downloadSourcesJob = new DownloadSourcesJob(this); + this.defaultDelegate = new DefaultClasspathManagerDelegate(); + } + + public static boolean isMaven2ClasspathContainer(IPath containerPath) { + return containerPath != null && containerPath.segmentCount() > 0 + && CONTAINER_ID.equals(containerPath.segment(0)); + } + + public static IClasspathEntry getDefaultContainerEntry() { + return JavaCore.newContainerEntry(new Path(CONTAINER_ID)); + } + + public static IClasspathEntry getMavenContainerEntry(IJavaProject javaProject) { + if(javaProject != null) { + try { + for(IClasspathEntry entry : javaProject.getRawClasspath()) { + if(isMaven2ClasspathContainer(entry.getPath())) { + return entry; + } + } + } catch(JavaModelException ex) { + return null; + } + } + return null; + } + + /** + XXX In Eclipse 3.3, changes to resolved classpath are not announced by JDT Core + and PackageExplorer does not properly refresh when we update Maven + classpath container. + As a temporary workaround, send F_CLASSPATH_CHANGED notifications + to all PackageExplorerContentProvider instances listening to + java ElementChangedEvent. + Note that even with this hack, build clean is sometimes necessary to + reconcile PackageExplorer with actual classpath + See https://bugs.eclipse.org/bugs/show_bug.cgi?id=154071 + */ + private void forcePackageExplorerRefresh(IJavaProject javaProject) { + if(getJDTVersion().startsWith("3.3")) { //$NON-NLS-1$ + DeltaProcessingState state = JavaModelManager.getJavaModelManager().deltaState; + synchronized(state) { + for(IElementChangedListener listener : state.elementChangedListeners) { + if(listener instanceof PackageExplorerContentProvider) { + JavaElementDelta delta = new JavaElementDelta(javaProject); + delta.changed(IJavaElementDelta.F_CLASSPATH_CHANGED); + listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE)); + } + } + } + } + } + + // XXX should inject version instead of looking it up + private synchronized String getJDTVersion() { + if(jdtVersion == null) { + Bundle[] bundles = bundleContext.getBundles(); + for(int i = 0; i < bundles.length; i++ ) { + if(JavaCore.PLUGIN_ID.equals(bundles[i].getSymbolicName())) { + jdtVersion = (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION); + break; + } + } + } + return jdtVersion; + } + + public static IClasspathContainer getMaven2ClasspathContainer(IJavaProject project) throws JavaModelException { + IClasspathEntry[] entries = project.getRawClasspath(); + for(int i = 0; i < entries.length; i++ ) { + IClasspathEntry entry = entries[i]; + if(entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && isMaven2ClasspathContainer(entry.getPath())) { + return JavaCore.getClasspathContainer(entry.getPath(), project); + } + } + return null; + } + + public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) { + Set<IProject> projects = new HashSet<IProject>(); + monitor.setTaskName(Messages.BuildPathManager_monitor_setting_cp); + for(int i = 0; i < events.length; i++ ) { + MavenProjectChangedEvent event = events[i]; + IFile pom = event.getSource(); + IProject project = pom.getProject(); + if(project.isAccessible() && projects.add(project)) { + updateClasspath(project, monitor); + } + } + } + + public void updateClasspath(IProject project, IProgressMonitor monitor) { + IJavaProject javaProject = JavaCore.create(project); + if(javaProject != null) { + try { + IClasspathEntry containerEntry = getMavenContainerEntry(javaProject); + IPath path = containerEntry != null ? containerEntry.getPath() : new Path(CONTAINER_ID); + IClasspathEntry[] classpath = getClasspath(project, monitor); + IClasspathContainer container = new MavenClasspathContainer(path, classpath); + JavaCore.setClasspathContainer(container.getPath(), new IJavaProject[] {javaProject}, + new IClasspathContainer[] {container}, monitor); + forcePackageExplorerRefresh(javaProject); + saveContainerState(project, container); + } catch(CoreException ex) { + MavenLogger.log(ex); + } + } + } + + private void saveContainerState(IProject project, IClasspathContainer container) { + File containerStateFile = getContainerStateFile(project); + FileOutputStream is = null; + try { + is = new FileOutputStream(containerStateFile); + new MavenClasspathContainerSaveHelper().writeContainer(container, is); + } catch(IOException ex) { + MavenLogger.log("Can't save classpath container state for " + project.getName(), ex); //$NON-NLS-1$ + } finally { + if(is != null) { + try { + is.close(); + } catch(IOException ex) { + MavenLogger.log("Can't close output stream for " + containerStateFile.getAbsolutePath(), ex); //$NON-NLS-1$ + } + } + } + } + + public IClasspathContainer getSavedContainer(IProject project) throws CoreException { + File containerStateFile = getContainerStateFile(project); + if(!containerStateFile.exists()) { + return null; + } + + FileInputStream is = null; + try { + is = new FileInputStream(containerStateFile); + return new MavenClasspathContainerSaveHelper().readContainer(is); + } catch(IOException ex) { + throw new CoreException(new Status(IStatus.ERROR, MavenJdtPlugin.PLUGIN_ID, -1, // + "Can't read classpath container state for " + project.getName(), ex)); + } catch(ClassNotFoundException ex) { + throw new CoreException(new Status(IStatus.ERROR, MavenJdtPlugin.PLUGIN_ID, -1, // + "Can't read classpath container state for " + project.getName(), ex)); + } finally { + if(is != null) { + try { + is.close(); + } catch(IOException ex) { + MavenLogger.log("Can't close output stream for " + containerStateFile.getAbsolutePath(), ex); //$NON-NLS-1$ + } + } + } + } + + private IClasspathEntry[] getClasspath(IMavenProjectFacade projectFacade, final int kind, + final Properties sourceAttachment, boolean uniquePaths, final IProgressMonitor monitor) throws CoreException { + + IJavaProject javaProject = JavaCore.create(projectFacade.getProject()); + + final ClasspathDescriptor classpath = new ClasspathDescriptor(javaProject); + + getDelegate(projectFacade, monitor).populateClasspath(classpath, projectFacade, kind, monitor); + + configureAttchedSourcesAndJavadoc(projectFacade, sourceAttachment, classpath, monitor); + + IClasspathEntry[] entries = classpath.getEntries(); + + if(uniquePaths) { + Map<IPath, IClasspathEntry> paths = new LinkedHashMap<IPath, IClasspathEntry>(); + for(IClasspathEntry entry : entries) { + if(!paths.containsKey(entry.getPath())) { + paths.put(entry.getPath(), entry); + } + } + return paths.values().toArray(new IClasspathEntry[paths.size()]); + } + + return entries; + } + + private IClasspathManagerDelegate getDelegate(IMavenProjectFacade projectFacade, IProgressMonitor monitor) + throws CoreException { + ILifecycleMapping lifecycleMapping = projectFacade.getLifecycleMapping(monitor); + if(lifecycleMapping instanceof IClasspathManagerDelegate) { + return (IClasspathManagerDelegate) lifecycleMapping; + } + return defaultDelegate; + } + + private void configureAttchedSourcesAndJavadoc(IMavenProjectFacade facade, Properties sourceAttachment, + ClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException { + for(IClasspathEntryDescriptor desc : classpath.getEntryDescriptors()) { + if(IClasspathEntry.CPE_LIBRARY == desc.getEntryKind() && desc.getSourceAttachmentPath() == null) { + ArtifactKey a = desc.getArtifactKey(); + String key = desc.getPath().toPortableString(); + + IPath srcPath = desc.getSourceAttachmentPath(); + IPath srcRoot = desc.getSourceAttachmentRootPath(); + if(srcPath == null && sourceAttachment != null && sourceAttachment.containsKey(key + PROPERTY_SRC_PATH)) { + srcPath = Path.fromPortableString((String) sourceAttachment.get(key + PROPERTY_SRC_PATH)); + if(sourceAttachment.containsKey(key + PROPERTY_SRC_ROOT)) { + srcRoot = Path.fromPortableString((String) sourceAttachment.get(key + PROPERTY_SRC_ROOT)); + } + } + if(srcPath == null && a != null) { + srcPath = getSourcePath(a); + } + + // configure javadocs if available + String javaDocUrl = desc.getJavadocUrl(); + if(javaDocUrl == null && sourceAttachment != null && sourceAttachment.containsKey(key + PROPERTY_JAVADOC_URL)) { + javaDocUrl = (String) sourceAttachment.get(key + PROPERTY_JAVADOC_URL); + } + if(javaDocUrl == null && a != null) { + javaDocUrl = getJavaDocUrl(a); + } + + desc.setSourceAttachment(srcPath, srcRoot); + desc.setJavadocUrl(javaDocUrl); + + ArtifactKey aKey = desc.getArtifactKey(); + if (aKey != null) { // maybe we should try to find artifactKey little harder here? + boolean downloadSources = desc.getSourceAttachmentPath() == null && srcPath == null + && mavenConfiguration.isDownloadSources(); + boolean downloadJavaDoc = desc.getJavadocUrl() == null && javaDocUrl == null + && mavenConfiguration.isDownloadJavaDoc(); + + scheduleDownload(facade.getProject(), facade.getMavenProject(), aKey, downloadSources, downloadJavaDoc); + } + } + } + } + + private boolean isUnavailable(ArtifactKey a, List<ArtifactRepository> repositories) throws CoreException { + return maven.isUnavailable(a.getGroupId(), a.getArtifactId(), a.getVersion(), "jar" /*type*/, a.getClassifier(), repositories); //$NON-NLS-1$ + } + +// public void downloadSources(IProject project, ArtifactKey artifact, boolean downloadSources, boolean downloadJavaDoc) throws CoreException { +// List<ArtifactRepository> repositories = null; +// IMavenProjectFacade facade = projectManager.getProject(project); +// if (facade != null) { +// MavenProject mavenProject = facade.getMavenProject(); +// if (mavenProject != null) { +// repositories = mavenProject.getRemoteArtifactRepositories(); +// } +// } +// doDownloadSources(project, artifact, downloadSources, downloadJavaDoc, repositories); +// } + + public IClasspathEntry[] getClasspath(IProject project, int scope, IProgressMonitor monitor) throws CoreException { + return getClasspath(project, scope, true, monitor); + } + + public IClasspathEntry[] getClasspath(IProject project, int scope, boolean uniquePaths, IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = projectManager.create(project, monitor); + if(facade == null) { + return new IClasspathEntry[0]; + } + try { + Properties props = new Properties(); + File file = getSourceAttachmentPropertiesFile(project); + if(file.canRead()) { + InputStream is = new BufferedInputStream(new FileInputStream(file)); + try { + props.load(is); + } finally { + is.close(); + } + } + return getClasspath(facade, scope, props, uniquePaths, monitor); + } catch(IOException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenJdtPlugin.PLUGIN_ID, -1, // + "Can't save classpath container changes", e)); + } + } + + public IClasspathEntry[] getClasspath(IProject project, IProgressMonitor monitor) throws CoreException { + return getClasspath(project, CLASSPATH_DEFAULT, monitor); + } + + /** + * Downloads artifact sources using background job. + * + * If path is null, downloads sources for all classpath entries of the project, + * otherwise downloads sources for the first classpath entry with the + * given path. + */ +// public void downloadSources(IProject project, IPath path) throws CoreException { +// downloadSourcesJob.scheduleDownload(project, path, findArtifacts(project, path), true, false); +// } + + /** + * Downloads artifact JavaDocs using background job. + * + * If path is null, downloads sources for all classpath entries of the project, + * otherwise downloads sources for the first classpath entry with the + * given path. + */ +// public void downloadJavaDoc(IProject project, IPath path) throws CoreException { +// downloadSourcesJob.scheduleDownload(project, path, findArtifacts(project, path), false, true); +// } + + private Set<ArtifactKey> findArtifacts(IProject project, IPath path) throws CoreException { + ArrayList<IClasspathEntry> entries = findClasspathEntries(project, path); + + Set<ArtifactKey> artifacts = new LinkedHashSet<ArtifactKey>(); + + for(IClasspathEntry entry : entries) { + ArtifactKey artifact = findArtifactByArtifactKey(entry); + + if(artifact == null) { + artifact = findArtifactInIndex(project, entry); + if(artifact == null) { + // console.logError("Can't find artifact for " + entry.getPath()); + } else { + // console.logMessage("Found indexed artifact " + artifact + " for " + entry.getPath()); + artifacts.add(artifact); + } + } else { + // console.logMessage("Found artifact " + artifact + " for " + entry.getPath()); + artifacts.add(artifact); + } + } + + return artifacts; + } + + public ArtifactKey findArtifact(IProject project, IPath path) throws CoreException { + if(path != null) { + Set<ArtifactKey> artifacts = findArtifacts(project, path); + // it is not possible to have more than one classpath entry with the same path + if(artifacts.size() > 0) { + return artifacts.iterator().next(); + } + } + return null; + } + + private ArtifactKey findArtifactByArtifactKey(IClasspathEntry entry) { + IClasspathAttribute[] attributes = entry.getExtraAttributes(); + String groupId = null; + String artifactId = null; + String version = null; + String classifier = null; + for(int j = 0; j < attributes.length; j++ ) { + if(GROUP_ID_ATTRIBUTE.equals(attributes[j].getName())) { + groupId = attributes[j].getValue(); + } else if(ARTIFACT_ID_ATTRIBUTE.equals(attributes[j].getName())) { + artifactId = attributes[j].getValue(); + } else if(VERSION_ATTRIBUTE.equals(attributes[j].getName())) { + version = attributes[j].getValue(); + } else if(CLASSIFIER_ATTRIBUTE.equals(attributes[j].getName())) { + classifier = attributes[j].getValue(); + } + } + + if(groupId != null && artifactId != null && version != null) { + return new ArtifactKey(groupId, artifactId, version, classifier); + } + return null; + } + + private ArtifactKey findArtifactInIndex(IProject project, IClasspathEntry entry) throws CoreException { + IFile jarFile = project.getWorkspace().getRoot().getFile(entry.getPath()); + File file = jarFile==null || jarFile.getLocation()==null ? entry.getPath().toFile() : jarFile.getLocation().toFile(); + + IndexedArtifactFile iaf = indexManager.getIndex(project).identify(file); + if(iaf != null) { + return new ArtifactKey(iaf.group, iaf.artifact, iaf.version, iaf.classifier); + } + + return null; + } + + // TODO should it be just one entry? + private ArrayList<IClasspathEntry> findClasspathEntries(IProject project, IPath path) throws JavaModelException { + ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); + + IJavaProject javaProject = JavaCore.create(project); + addEntries(entries, javaProject.getRawClasspath(), path); + + IClasspathContainer container = getMaven2ClasspathContainer(javaProject); + if(container != null) { + addEntries(entries, container.getClasspathEntries(), path); + } + return entries; + } + + private void addEntries(Collection<IClasspathEntry> collection, IClasspathEntry[] entries, IPath path) { + for(IClasspathEntry entry : entries) { + if(entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && (path == null || path.equals(entry.getPath()))) { + collection.add(entry); + } + } + } + + /** + * Extracts and persists custom source/javadoc attachment info + */ + public void persistAttachedSourcesAndJavadoc(IJavaProject project, IClasspathContainer containerSuggestion, + IProgressMonitor monitor) throws CoreException { + IFile pom = project.getProject().getFile(IMavenConstants.POM_FILE_NAME); + IMavenProjectFacade facade = projectManager.create(pom, false, null); + if(facade == null) { + return; + } + + // collect all source/javadoc attachement + Properties props = new Properties(); + IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); + for(int i = 0; i < entries.length; i++ ) { + IClasspathEntry entry = entries[i]; + if(IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) { + String path = entry.getPath().toPortableString(); + if(entry.getSourceAttachmentPath() != null) { + props.put(path + PROPERTY_SRC_PATH, entry.getSourceAttachmentPath().toPortableString()); + } + if(entry.getSourceAttachmentRootPath() != null) { + props.put(path + PROPERTY_SRC_ROOT, entry.getSourceAttachmentRootPath().toPortableString()); + } + String javadocUrl = getJavadocLocation(entry); + if(javadocUrl != null) { + props.put(path + PROPERTY_JAVADOC_URL, javadocUrl); + } + } + } + + // eliminate all "standard" source/javadoc attachement we get from local repo + entries = getClasspath(facade, CLASSPATH_DEFAULT, null, true, monitor); + for(int i = 0; i < entries.length; i++ ) { + IClasspathEntry entry = entries[i]; + if(IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) { + String path = entry.getPath().toPortableString(); + String value = (String) props.get(path + PROPERTY_SRC_PATH); + if (value != null && entry.getSourceAttachmentPath() != null && value.equals(entry.getSourceAttachmentPath().toPortableString())) { + props.remove(path + PROPERTY_SRC_PATH); + } + value = (String) props.get(path + PROPERTY_SRC_ROOT); + if (value != null && entry.getSourceAttachmentRootPath() != null && value.equals(entry.getSourceAttachmentRootPath().toPortableString())) { + props.remove(path + PROPERTY_SRC_ROOT); + } + } + } + + // persist custom source/javadoc attachement info + File file = getSourceAttachmentPropertiesFile(project.getProject()); + try { + OutputStream os = new BufferedOutputStream(new FileOutputStream(file)); + try { + props.store(os, null); + } finally { + os.close(); + } + } catch(IOException e) { + throw new CoreException(new Status(IStatus.ERROR, MavenJdtPlugin.PLUGIN_ID, -1, "Can't save classpath container changes", e)); + } + + // update classpath container. suboptimal as this will re-calculate classpath + updateClasspath(project.getProject(), monitor); + } + + /** public for unit tests only */ + public String getJavadocLocation(IClasspathEntry entry) { + IClasspathAttribute[] attributes = entry.getExtraAttributes(); + for(int j = 0; j < attributes.length; j++ ) { + IClasspathAttribute attribute = attributes[j]; + if(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attribute.getName())) { + return attribute.getValue(); + } + } + return null; + } + + /** public for unit tests only */ + public File getSourceAttachmentPropertiesFile(IProject project) { + return new File(stateLocationDir, project.getName() + ".sources"); //$NON-NLS-1$ + } + + /** public for unit tests only */ + public File getContainerStateFile(IProject project) { + return new File(stateLocationDir, project.getName() + ".container"); //$NON-NLS-1$ + } + + public void resourceChanged(IResourceChangeEvent event) { + int type = event.getType(); + if(IResourceChangeEvent.PRE_DELETE == type) { + // remove custom source and javadoc configuration + File attachmentProperties = getSourceAttachmentPropertiesFile((IProject) event.getResource()); + if(attachmentProperties.exists() && !attachmentProperties.delete()) { + MavenLogger.log("Can't delete " + attachmentProperties.getAbsolutePath(), null); //$NON-NLS-1$ + } + + // remove classpath container state + File containerState = getContainerStateFile((IProject) event.getResource()); + if(containerState.exists() && !containerState.delete()) { + MavenLogger.log("Can't delete " + containerState.getAbsolutePath(), null); //$NON-NLS-1$ + } + } + } + + public boolean setupVariables() { + boolean changed = false; + try { + File localRepositoryDir = new File(maven.getLocalRepository().getBasedir()); + IPath oldPath = JavaCore.getClasspathVariable(M2_REPO); + IPath newPath = new Path(localRepositoryDir.getAbsolutePath()); + JavaCore.setClasspathVariable(M2_REPO, // + newPath, // + new NullProgressMonitor()); + changed = !newPath.equals(oldPath); + } catch(CoreException ex) { + MavenLogger.log(ex); + changed = false; + } + return changed; + } + + public boolean variablesAreInUse() { + try { + IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); + IJavaProject[] projects = model.getJavaProjects(); + for(int i = 0; i < projects.length; i++ ) { + IClasspathEntry[] entries = projects[i].getRawClasspath(); + for(int k = 0; k < entries.length; k++ ) { + IClasspathEntry curr = entries[k]; + if(curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { + String var = curr.getPath().segment(0); + if(M2_REPO.equals(var)) { + return true; + } + } + } + } + } catch(JavaModelException e) { + return true; + } + return false; + } + + static String getSourcesClassifier(String baseClassifier) { + return BuildPathManager.CLASSIFIER_TESTS.equals(baseClassifier) ? BuildPathManager.CLASSIFIER_TESTSOURCES + : BuildPathManager.CLASSIFIER_SOURCES; + } + + private IPath getSourcePath(ArtifactKey a) { + File file = getAttachedArtifactFile(a, getSourcesClassifier(a.getClassifier())); + + if(file != null) { + return Path.fromOSString(file.getAbsolutePath()); + } + + return null; + } + + /** + * Resolves artifact from local repository. Returns null if the artifact is not available locally + */ + private File getAttachedArtifactFile(ArtifactKey a, String classifier) { + // can't use Maven resolve methods since they mark artifacts as not-found even if they could be resolved remotely + try { + ArtifactRepository localRepository = maven.getLocalRepository(); + String relPath = maven.getArtifactPath(localRepository, a.getGroupId(), a.getArtifactId(), a.getVersion(), + "jar", classifier); //$NON-NLS-1$ + File file = new File(localRepository.getBasedir(), relPath).getCanonicalFile(); + if(file.canRead()) { + return file; + } + } catch(CoreException ex) { + // fall through + } catch(IOException ex) { + // fall through + } + return null; + } + + private String getJavaDocUrl(ArtifactKey base) { + File file = getAttachedArtifactFile(base, CLASSIFIER_JAVADOC); + + return getJavaDocUrl(file); + } + + static String getJavaDocUrl(File file) { + try { + if(file != null) { + URL fileUrl = file.toURL(); + return "jar:" + fileUrl.toExternalForm() + "!/" + getJavaDocPathInArchive(file); //$NON-NLS-1$ //$NON-NLS-2$ + } + } catch(MalformedURLException ex) { + // fall through + } + + return null; + } + + private static String getJavaDocPathInArchive(File file) { + ZipFile jarFile = null; + try { + jarFile = new ZipFile(file); + String marker = "package-list"; //$NON-NLS-1$ + for(Enumeration<? extends ZipEntry> en = jarFile.entries(); en.hasMoreElements();) { + ZipEntry entry = en.nextElement(); + String entryName = entry.getName(); + if(entryName.endsWith(marker)) { + return entry.getName().substring(0, entryName.length() - marker.length()); + } + } + } catch(IOException ex) { + // ignore + } finally { + try { + if(jarFile != null) + jarFile.close(); + } catch(IOException ex) { + // + } + } + + return ""; //$NON-NLS-1$ + } + + /** + * this is for unit tests only! + */ + public Job getDownloadSourcesJob() { + return downloadSourcesJob; + } + + public void scheduleDownload(IPackageFragmentRoot fragment, boolean downloadSources, boolean downloadJavadoc) { + ArtifactKey artifact = (ArtifactKey) fragment.getAdapter(ArtifactKey.class); + + if(artifact == null) { + // we don't know anything about this JAR/ZIP + return; + } + + IProject project = fragment.getJavaProject().getProject(); + + try { + if(project.hasNature(IMavenConstants.NATURE_ID)) { + IMavenProjectFacade facade = projectManager.getProject(project); + MavenProject mavenProject = facade != null ? facade.getMavenProject() : null; + if(mavenProject != null) { + scheduleDownload(project, mavenProject, artifact, downloadSources, downloadJavadoc); + } else { + downloadSourcesJob.scheduleDownload(project, artifact, downloadSources, downloadJavadoc); + } + } else { + // this is a non-maven project + List<ArtifactRepository> repositories = maven.getArtifactRepositories(); + ArtifactKey[] attached = getAttachedSourcesAndJavadoc(artifact, repositories, downloadSources, downloadJavadoc); + + if(attached[0] != null || attached[1] != null) { + downloadSourcesJob.scheduleDownload(fragment, artifact, downloadSources, downloadJavadoc); + } + } + } catch(CoreException e) { + MavenLogger.log("Could not schedule sources/javadoc download", e); //$NON-NLS-1$ + } + + } + + public void scheduleDownload(final IProject project, final boolean downloadSources, final boolean downloadJavadoc) { + try { + if(project != null && project.isAccessible() && project.hasNature(IMavenConstants.NATURE_ID)) { + IMavenProjectFacade facade = projectManager.getProject(project); + MavenProject mavenProject = facade != null ? facade.getMavenProject() : null; + if(mavenProject != null) { + for(Artifact artifact : mavenProject.getArtifacts()) { + ArtifactKey artifactKey = new ArtifactKey(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getClassifier()); + scheduleDownload(project, mavenProject, artifactKey, downloadSources, downloadJavadoc); + } + } else { + // project is not in the cache, push all processing to the background job + downloadSourcesJob.scheduleDownload(project, null, downloadSources, downloadJavadoc); + } + } + } catch(CoreException e) { + MavenLogger.log("Could not schedule sources/javadoc download", e); //$NON-NLS-1$ + } + } + + private void scheduleDownload(IProject project, MavenProject mavenProject, ArtifactKey artifact, boolean downloadSources, boolean downloadJavadoc) throws CoreException { + ArtifactKey[] attached = getAttachedSourcesAndJavadoc(artifact, mavenProject.getRemoteArtifactRepositories(), downloadSources, downloadJavadoc); + + if(attached[0] != null || attached[1] != null) { + downloadSourcesJob.scheduleDownload(project, artifact, downloadSources, downloadJavadoc); + } + } + + ArtifactKey[] getAttachedSourcesAndJavadoc(ArtifactKey a, List<ArtifactRepository> repositories, boolean downloadSources, boolean downloadJavaDoc) throws CoreException { + ArtifactKey sourcesArtifact = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getVersion(), getSourcesClassifier(a.getClassifier())); + ArtifactKey javadocArtifact = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getVersion(), CLASSIFIER_JAVADOC); + + if(repositories != null) { + downloadSources &= !isUnavailable(sourcesArtifact, repositories); + downloadJavaDoc &= !isUnavailable(javadocArtifact, repositories); + } + + ArtifactKey[] result = new ArtifactKey[2]; + + if(downloadSources) { + result[0] = sourcesArtifact; + } + + if(downloadJavaDoc) { + result[1] = javadocArtifact; + } + + return result; + } + + void attachSourcesAndJavadoc(IPackageFragmentRoot fragment, File sources, File javadoc, IProgressMonitor monitor) { + IJavaProject javaProject = fragment.getJavaProject(); + + IPath srcPath = sources != null ? Path.fromOSString(sources.getAbsolutePath()) : null; + String javaDocUrl = getJavaDocUrl(javadoc); + + try { + IClasspathEntry[] cp = javaProject.getRawClasspath(); + for(int i = 0; i < cp.length; i++ ) { + IClasspathEntry entry = cp[i]; + if(IClasspathEntry.CPE_LIBRARY == entry.getEntryKind() && entry.equals(fragment.getRawClasspathEntry())) { + List<IClasspathAttribute> attributes = new ArrayList<IClasspathAttribute>(Arrays.asList(entry.getExtraAttributes())); + + if(srcPath == null) { + // configure javadocs if available + if(javaDocUrl != null) { + attributes.add(JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, + javaDocUrl)); + } + } + + cp[i] = JavaCore.newLibraryEntry(entry.getPath(), srcPath, null, entry.getAccessRules(), // + attributes.toArray(new IClasspathAttribute[attributes.size()]), // + entry.isExported()); + + break; + } + } + + javaProject.setRawClasspath(cp, monitor); + } catch(CoreException e) { + MavenLogger.log(e); + } + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/DownloadSourcesActionDelegate.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/DownloadSourcesActionDelegate.java new file mode 100644 index 00000000..c9b1428f --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/DownloadSourcesActionDelegate.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.m2e.jdt; + +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorActionDelegate; +import org.eclipse.ui.IEditorPart; + +import org.eclipse.m2e.core.core.MavenLogger; + +/** + * + * DownloadSourcesActionDelegate + * + * @author Anton Kraev + */ + +@SuppressWarnings("restriction") +public class DownloadSourcesActionDelegate implements IEditorActionDelegate { + + public void setActiveEditor(IAction action, IEditorPart part) { + + if (part != null) { + try { + BuildPathManager buildpathManager = MavenJdtPlugin .getDefault().getBuildpathManager(); + + IClassFileEditorInput input = (IClassFileEditorInput) part.getEditorInput(); + IJavaElement element = input.getClassFile(); + while (element.getParent() != null) { + element = element.getParent(); + if (element instanceof IPackageFragmentRoot) { + IPackageFragmentRoot root = (IPackageFragmentRoot) element; + + if (root.getSourceAttachmentPath() != null) { + // do nothing if sources attached already + break; + } + + buildpathManager.scheduleDownload(root, true/*sources*/, false/*javadoc*/); + } + } + } catch(Exception ex) { + MavenLogger.log("Could not schedule source download", ex); //$NON-NLS-1$ + } + } + } + + public void run(IAction action) { + // no need to do anything + } + + public void selectionChanged(IAction action, ISelection selection) { + // no need to do anything + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/DownloadSourcesJob.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/DownloadSourcesJob.java new file mode 100644 index 00000000..737fd9bb --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/DownloadSourcesJob.java @@ -0,0 +1,270 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt; + +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.IPackageFragmentRoot; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.project.MavenProject; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.MavenConsole; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.jobs.IBackgroundProcessingQueue; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.jdt.internal.Messages; + + +/** + * DownloadSourcesJob + * + * @author igor + */ +class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue { + + private static class DownloadRequest { + final IProject project; + + final IPackageFragmentRoot fragment; + + final ArtifactKey artifact; + + final boolean downloadSources; + + final boolean downloadJavaDoc; + + public DownloadRequest(IProject project, IPackageFragmentRoot fragment, ArtifactKey artifact, boolean downloadSources, + boolean downloadJavaDoc) { + this.project = project; + this.fragment = fragment; + this.artifact = artifact; + this.downloadSources = downloadSources; + this.downloadJavaDoc = downloadJavaDoc; + } + + public int hashCode() { + int hash = 17; + hash = hash * 31 + project.hashCode(); + hash = hash * 31 + (fragment != null? fragment.hashCode(): 0); + hash = hash * 31 + (artifact != null? artifact.hashCode(): 0); + hash = hash * 31 + (downloadSources ? 1 : 0); + hash = hash * 31 + (downloadJavaDoc ? 1 : 0); + return hash; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DownloadRequest)) { + return false; + } + DownloadRequest other = (DownloadRequest) o; + + return project.equals(other.project) + && (fragment != null? fragment.equals(other.fragment): other.fragment == null) + && (artifact != null? artifact.equals(other.artifact): other.artifact == null) + && downloadSources == other.downloadSources + && downloadJavaDoc == other.downloadJavaDoc; + } + } + + private final IMaven maven; + + private final BuildPathManager manager; + + private final MavenConsole console; + + private final MavenProjectManager projectManager; + + private final ArrayList<DownloadRequest> queue = new ArrayList<DownloadRequest>(); + + public DownloadSourcesJob(BuildPathManager manager) { + super(Messages.DownloadSourcesJob_job_download); + this.manager = manager; + + this.maven = MavenPlugin.getDefault().getMaven(); + + MavenPlugin plugin = MavenPlugin.getDefault(); + this.projectManager = plugin.getMavenProjectManager(); + this.console = plugin.getConsole(); + } + + public IStatus run(IProgressMonitor monitor) { + ArrayList<DownloadRequest> downloadRequests; + + synchronized(this.queue) { + downloadRequests = new ArrayList<DownloadRequest>(this.queue); + this.queue.clear(); + } + + ArrayList<IStatus> exceptions = new ArrayList<IStatus>(); + + Set<IProject> mavenProjects = new LinkedHashSet<IProject>(); + Map<IPackageFragmentRoot, File[]> nonMavenProjects = new LinkedHashMap<IPackageFragmentRoot, File[]>(); + + for(DownloadRequest request : downloadRequests) { + if ( request.artifact != null ) try { + IMavenProjectFacade projectFacade = projectManager.create(request.project, monitor); + + if (projectFacade != null) { + downloadMaven(projectFacade, request.artifact, request.downloadSources, request.downloadJavaDoc, monitor); + mavenProjects.add(request.project); + } else { + List<ArtifactRepository> repositories = maven.getArtifactRepositories(); + + File[] files = downloadAttachments(request.artifact, repositories, request.downloadSources, request.downloadJavaDoc, monitor); + + nonMavenProjects.put(request.fragment, files); + } + } catch(CoreException ex) { + exceptions.add(ex.getStatus()); + } + } + + if(!mavenProjects.isEmpty() || !nonMavenProjects.isEmpty()) { + ISchedulingRule schedulingRule = ResourcesPlugin.getWorkspace().getRuleFactory().buildRule(); + getJobManager().beginRule(schedulingRule, monitor); + try { + for (IProject mavenProject : mavenProjects) { + manager.updateClasspath(mavenProject, monitor); + } + + for (Map.Entry<IPackageFragmentRoot, File[]> entry : nonMavenProjects.entrySet()) { + File[] files = entry.getValue(); + manager.attachSourcesAndJavadoc(entry.getKey(), files[0], files[1], monitor); + } + } finally { + getJobManager().endRule(schedulingRule); + } + } + + if(!exceptions.isEmpty()) { + IStatus[] problems = exceptions.toArray(new IStatus[exceptions.size()]); + return new MultiStatus(MavenJdtPlugin.PLUGIN_ID, -1, problems, "Could not download sources or javadoc", null); + } + + return Status.OK_STATUS; + } + + private void downloadMaven(IMavenProjectFacade projectFacade, ArtifactKey artifact, boolean downloadSources, boolean downloadJavadoc, IProgressMonitor monitor) throws CoreException { + MavenProject mavenProject = projectFacade.getMavenProject(monitor); + List<ArtifactRepository> repositories = mavenProject.getRemoteArtifactRepositories(); + + if (artifact != null) { + downloadAttachments(artifact, repositories, downloadSources, downloadJavadoc, monitor); + } else { + for (Artifact a : mavenProject.getArtifacts()) { + ArtifactKey aKey = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier()); + downloadAttachments(aKey, repositories, downloadSources, downloadJavadoc, monitor); + } + } + } + + private File[] downloadAttachments(ArtifactKey artifact, List<ArtifactRepository> repositories, boolean downloadSources, + boolean downloadJavadoc, IProgressMonitor monitor) throws CoreException { + + ArtifactKey[] attached = manager.getAttachedSourcesAndJavadoc(artifact, repositories, downloadSources, downloadJavadoc); + + File[] files = new File[2]; + + if (attached[0] != null) { + try { + files[0] = download(attached[0], repositories, monitor); + console.logMessage("Downloaded sources for " + artifact.toString()); + } catch (CoreException e) { + logMessage("Could not download sources for " + artifact.toString(), e); //$NON-NLS-1$ + } + } + + if (attached[1] != null) { + try { + files[1] = download(attached[1], repositories, monitor); + console.logMessage("Downloaded javadoc for " + artifact.toString()); + } catch (CoreException e) { + logMessage("Could not download sources for " + artifact.toString(), e); //$NON-NLS-1$ + } + } + + return files; + } + + private File download(ArtifactKey artifact, List<ArtifactRepository> repositories, IProgressMonitor monitor) throws CoreException { + Artifact resolved = maven.resolve(artifact.getGroupId(), // + artifact.getArtifactId(), // + artifact.getVersion(), // + "jar" /*type*/, // //$NON-NLS-1$ + artifact.getClassifier(), // + repositories, // + monitor); + return resolved.getFile(); + } + + private void logMessage(String msg, CoreException e) { + MavenLogger.log(msg, e); + console.logMessage(msg); + } + + private void scheduleDownload(IProject project, IPackageFragmentRoot fragment, ArtifactKey artifact, boolean downloadSources, boolean downloadJavadoc) { + if (project == null || !project.isAccessible()) { + return; + } + + synchronized(this.queue) { + queue.add(new DownloadRequest(project, fragment, artifact, downloadSources, downloadJavadoc)); + } + + schedule(1000L); + } + + /** + * If artifact is not null, download sources and/or javadoc of this artifact. + * If artifact is null, download sources and/or javadoc of all project dependencies. + * Entire project classpath is updated after download. + * Does nothing if both downloadSources and downloadJavadoc are false. + */ + public void scheduleDownload(IProject project, ArtifactKey artifact, boolean downloadSources, boolean downloadJavadoc) { + scheduleDownload(project, null, artifact, downloadSources, downloadJavadoc); + } + + public void scheduleDownload(IPackageFragmentRoot fragment, ArtifactKey artifact, boolean downloadSources, boolean downloadJavadoc) { + IProject project = fragment.getJavaProject().getProject(); + scheduleDownload(project, fragment, artifact, downloadSources, downloadJavadoc); + } + + public boolean isEmpty() { + synchronized(queue) { + return queue.isEmpty(); + } + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java new file mode 100644 index 00000000..426dd3aa --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt; + +import java.util.List; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IClasspathEntry; + +import org.apache.maven.artifact.Artifact; + +import org.eclipse.m2e.core.project.IMavenProjectFacade; + + +/** + * Instances of this class can be used to incrementally define IClasspathEntry[] arrays used by JDT to decribe Java + * Project classpath and contents of Java classpath containers. + * + * @author igor + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IClasspathDescriptor { + + public static interface EntryFilter { + public boolean accept(IClasspathEntryDescriptor descriptor); + } + + /** + * @return true if classpath contains entry with specified path, false otherwise. + */ + public boolean containsPath(IPath path); + + /** + * Convenience method, equivalent to + * <code>addSourceEntry(sourcePath, outputLocation, new IPath[0], new IPath[0], generated)</code> + */ + public IClasspathEntryDescriptor addSourceEntry(IPath sourcePath, IPath outputLocation, boolean generated); + + /** + * Adds project source folder to the classpath. The source folder must exist in the workspace unless generated is + * true. In the latter case, the source classpath entry will be marked as optional. + */ + public IClasspathEntryDescriptor addSourceEntry(IPath sourcePath, IPath outputLocation, IPath[] inclusion, + IPath[] exclusion, boolean generated); + + /** + * Adds fully populated IClasspathEntry instance to the classpath. + */ + public IClasspathEntryDescriptor addEntry(IClasspathEntry entry); + + /** + * Adds and returns new project classpath entry. + */ + public IClasspathEntryDescriptor addProjectEntry(IPath entryPath); + + /** + * Adds and returns new library entry to the classpath + */ + public IClasspathEntryDescriptor addLibraryEntry(IPath entryPath); + + /** + * Removes entry with specified path from the classpath. That this can remove multiple entries because classpath does + * not enforce uniqueness of entry paths + * + * @TODO should really be removeEntries (i.e. plural) + */ + public List<IClasspathEntryDescriptor> removeEntry(IPath path); + + /** + * Removed entries that match EntryFilter (i.e. EntryFilter#accept(entry) returns true) from the classpath + * + * @TODO should really be removeEntries (i.e. plural) + */ + public List<IClasspathEntryDescriptor> removeEntry(EntryFilter filter); + + /** + * Renders classpath as IClasspathEntry[] array + * + * @TODO should really be toEntriesArray + */ + public IClasspathEntry[] getEntries(); + + /** + * Returns underlying "live" list of IClasspathEntryDescriptor instances. Changes to the list will be immediately + * reflected in the classpath. + */ + public List<IClasspathEntryDescriptor> getEntryDescriptors(); + + // deprecated, to be removed before 1.0 + + /** + * Adds Maven artifact with corresponding sources and javadoc paths to the classpath. + * + * @deprecated this method exposes Maven core classes, which are not part of m2eclipse-jdt API + */ + public IClasspathEntryDescriptor addLibraryEntry(Artifact artifact, IPath srcPath, IPath srcRoot, String javaDocUrl); + + /** + * Adds worksapce Maven project dependency to the classpath + * + * @deprecated this method exposes Maven core classes, which are not part of m2eclipse-jdt API + */ + public IClasspathEntryDescriptor addProjectEntry(Artifact artifact, IMavenProjectFacade projectFacade); +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java new file mode 100644 index 00000000..47cf3343 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IAccessRule; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; + +import org.eclipse.m2e.core.embedder.ArtifactKey; + + +/** + * Mutable version of IClasspathEntry with additional Maven specific attributes. + * + * @author igor + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IClasspathEntryDescriptor { + + // classpath entry getters and setters (open a bug if you need any of the missing getters/setters) + + public void setClasspathAttribute(String name, String value); + + public IPath getPath(); + + public int getEntryKind(); + + public void setSourceAttachment(IPath srcPath, IPath srcRoot); + + public void setJavadocUrl(String javaDocUrl); + + public IPath getSourceAttachmentPath(); + + public IPath getSourceAttachmentRootPath(); + + public String getJavadocUrl(); + + public void setOutputLocation(IPath outputLocation); + + public void setInclusionPatterns(IPath[] inclusionPatterns); + + public void addInclusionPattern(IPath pattern); + + public void setExclusionPatterns(IPath[] exclusionPatterns); + + public IPath[] getInclusionPatterns(); + + public void addExclusionPattern(IPath pattern); + + public IPath[] getExclusionPatterns(); + + // maven-specific getters and setters + + /** + * Short for getArtifactKey().getGroupId(), with appropriate null check + */ + public String getGroupId(); + + public void addAccessRule(IAccessRule rule); + + /** + * Short for getArtifactKey().getArtifactId(), with appropriate null check + */ + public String getArtifactId(); + + public ArtifactKey getArtifactKey(); + + public void setArtifactKey(ArtifactKey artifactKey); + + /** + * @return true if this entry corresponds to an optional maven dependency, false otherwise + */ + public boolean isOptionalDependency(); + + public void setOptionalDependency(boolean optional); + + public String getScope(); + + public void setScope(String scope); + + // + + /** + * Create IClasspathEntry with information collected in this descriptor + */ + public IClasspathEntry toClasspathEntry(); + + // deprecated methods, to be removed before 1.0 + + /** + * @deprecated use individual setter methods instead + */ + public void setClasspathEntry(IClasspathEntry entry); + + /** + * @deprecated use {@link #setClasspathAttribute(String, String)} instead + */ + public void addClasspathAttribute(IClasspathAttribute attribute); + + /** + * @deprecated use {@link #toClasspathEntry()} instead + */ + public IClasspathEntry getClasspathEntry(); + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathManagerDelegate.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathManagerDelegate.java new file mode 100644 index 00000000..28035f07 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathManagerDelegate.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.m2e.core.project.IMavenProjectFacade; + +/** + * IBuildPathManagerDelegate + * + * @author igor + */ +public interface IClasspathManagerDelegate { + + public void populateClasspath(IClasspathDescriptor classpath, IMavenProjectFacade projectFacade, int kind, + IProgressMonitor monitor) throws CoreException; + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IJavaProjectConfigurator.java new file mode 100644 index 00000000..bcbb8bc2 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IJavaProjectConfigurator.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; + + +/** + * IJavaProjectConfigurator + * + * @author igor + */ +public interface IJavaProjectConfigurator { + + /** + * Configures *Maven* project classpath, i.e. content of Maven Dependencies classpath container. + */ + public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException; + + /** + * Configures *JDT* project classpath, i.e. project-level entries like source folders, JRE and Maven Dependencies + * classpath container. + */ + public void configureRawClasspath(ProjectConfigurationRequest request, IClasspathDescriptor classpath, + IProgressMonitor monitor) throws CoreException; +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java new file mode 100644 index 00000000..3f269c61 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + + +/******************************************************************************* + * Copyright (c) 2008 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ + +package org.eclipse.m2e.jdt; + +import java.io.File; + +import org.osgi.framework.BundleContext; + +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.resources.WorkspaceJob; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.MavenConsole; +import org.eclipse.m2e.core.embedder.AbstractMavenConfigurationChangeListener; +import org.eclipse.m2e.core.embedder.IMavenConfiguration; +import org.eclipse.m2e.core.embedder.MavenConfigurationChangeEvent; +import org.eclipse.m2e.core.index.IndexManager; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.jdt.internal.Messages; +import org.eclipse.m2e.jdt.internal.launch.MavenLaunchConfigurationListener; + + +public class MavenJdtPlugin extends AbstractUIPlugin { + + public static String PLUGIN_ID = "org.eclipse.m2e.jdt"; //$NON-NLS-1$ + + private static MavenJdtPlugin instance; + + MavenLaunchConfigurationListener launchConfigurationListener; + BuildPathManager buildpathManager; + + public MavenJdtPlugin() { + instance = this; + + if(Boolean.parseBoolean(Platform.getDebugOption(PLUGIN_ID + "/debug/initialization"))) { //$NON-NLS-1$ + System.err.println("### executing constructor " + PLUGIN_ID); //$NON-NLS-1$ + new Throwable().printStackTrace(); + } + } + + public void start(BundleContext bundleContext) throws Exception { + if(Boolean.parseBoolean(Platform.getDebugOption(PLUGIN_ID + "/debug/initialization"))) { //$NON-NLS-1$ + System.err.println("### executing start() " + PLUGIN_ID); //$NON-NLS-1$ + new Throwable().printStackTrace(); + } + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + MavenPlugin mavenPlugin = MavenPlugin.getDefault(); + + MavenProjectManager projectManager = mavenPlugin.getMavenProjectManager(); + MavenConsole console = mavenPlugin.getConsole(); + IndexManager indexManager = mavenPlugin.getIndexManager(); + IMavenConfiguration mavenConfiguration = MavenPlugin.getDefault().getMavenConfiguration(); + + File stateLocationDir = mavenPlugin.getStateLocation().toFile(); // TODO migrate JDT settings to this plugin's store + + this.buildpathManager = new BuildPathManager(console, projectManager, indexManager, bundleContext, stateLocationDir); + workspace.addResourceChangeListener(buildpathManager, IResourceChangeEvent.PRE_DELETE); + + projectManager.addMavenProjectChangedListener(this.buildpathManager); + + mavenConfiguration.addConfigurationChangeListener(new AbstractMavenConfigurationChangeListener() { + public void mavenConfigutationChange(MavenConfigurationChangeEvent event) { + if (!MavenConfigurationChangeEvent.P_USER_SETTINGS_FILE.equals(event.getKey())) { + return; + } + + if (buildpathManager.setupVariables() && buildpathManager.variablesAreInUse()) { + WorkspaceJob job = new WorkspaceJob(Messages.MavenJdtPlugin_job_name) { + + public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, monitor); + return Status.OK_STATUS; + } + + }; + job.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); + job.schedule(); + }}}); + + this.launchConfigurationListener = new MavenLaunchConfigurationListener(); + DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(launchConfigurationListener); + projectManager.addMavenProjectChangedListener(launchConfigurationListener); + } + + public void stop(BundleContext context) throws Exception { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + MavenPlugin mavenPlugin = MavenPlugin.getDefault(); + + MavenProjectManager projectManager = mavenPlugin.getMavenProjectManager(); + projectManager.removeMavenProjectChangedListener(buildpathManager); + + workspace.removeResourceChangeListener(this.buildpathManager); + + DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(launchConfigurationListener); + projectManager.removeMavenProjectChangedListener(launchConfigurationListener); + + this.buildpathManager = null; + this.launchConfigurationListener = null; + } + + public static MavenJdtPlugin getDefault() { + return instance; + } + + public BuildPathManager getBuildpathManager() { + return buildpathManager; + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java new file mode 100644 index 00000000..1683672c --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java @@ -0,0 +1,481 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.environments.IExecutionEnvironment; +import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.IProjectConfigurationManager; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ILifecycleMapping; +import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest; +import org.eclipse.m2e.core.util.Util; +import org.eclipse.m2e.jdt.BuildPathManager; +import org.eclipse.m2e.jdt.IClasspathDescriptor; +import org.eclipse.m2e.jdt.IClasspathEntryDescriptor; +import org.eclipse.m2e.jdt.IJavaProjectConfigurator; +import org.eclipse.m2e.jdt.MavenJdtPlugin; + + +/** + * AbstractJavaProjectConfigurator + * + * @author igor + */ +public abstract class AbstractJavaProjectConfigurator extends AbstractProjectConfigurator { + + protected static final List<String> SOURCES = Arrays.asList("1.1,1.2,1.3,1.4,1.5,1.6,1.7".split(",")); //$NON-NLS-1$ //$NON-NLS-2$ + + protected static final List<String> TARGETS = Arrays.asList("1.1,1.2,1.3,1.4,jsr14,1.5,1.6,1.7".split(",")); //$NON-NLS-1$ //$NON-NLS-2$ + + protected static final LinkedHashMap<String, String> ENVIRONMENTS = new LinkedHashMap<String, String>(); + + static { + ENVIRONMENTS.put("1.1", "JRE-1.1"); //$NON-NLS-1$ //$NON-NLS-2$ + ENVIRONMENTS.put("1.2", "J2SE-1.2"); //$NON-NLS-1$ //$NON-NLS-2$ + ENVIRONMENTS.put("1.3", "J2SE-1.3"); //$NON-NLS-1$ //$NON-NLS-2$ + ENVIRONMENTS.put("1.4", "J2SE-1.4"); //$NON-NLS-1$ //$NON-NLS-2$ + ENVIRONMENTS.put("1.5", "J2SE-1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + ENVIRONMENTS.put("jsr14", "J2SE-1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + ENVIRONMENTS.put("1.6", "JavaSE-1.6"); //$NON-NLS-1$ //$NON-NLS-2$ + ENVIRONMENTS.put("1.7", "JavaSE-1.7"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + protected static final String DEFAULT_COMPILER_LEVEL = "1.4"; //$NON-NLS-1$ + + public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { + IProject project = request.getProject(); + + monitor.setTaskName(Messages.AbstractJavaProjectConfigurator_task_name + project.getName()); + + addJavaNature(project, monitor); + + IJavaProject javaProject = JavaCore.create(project); + + MavenProject mavenProject = getMavenProject(request, monitor); + + Map<String, String> options = new HashMap<String, String>(); + + addJavaProjectOptions(options, request, mavenProject, monitor); + + IClasspathDescriptor classpath = new ClasspathDescriptor(javaProject); + + addProjectSourceFolders(classpath, request, mavenProject, monitor); + + String environmentId = getExecutionEnvironmentId(options); + + addJREClasspathContainer(classpath, environmentId); + + addMavenClasspathContainer(classpath); + + addCustomClasspathEntries(javaProject, classpath); + + invokeJavaProjectConfigurators(classpath, request, monitor); + + // now apply new configuration + + // A single setOptions call erases everything else from an existing settings file. + // Must invoke setOption individually to preserve previous options. + for(Map.Entry<String, String> option : options.entrySet()) { + javaProject.setOption(option.getKey(), option.getValue()); + } + + IContainer classesFolder = getFolder(project, mavenProject.getBuild().getOutputDirectory()); + + javaProject.setRawClasspath(classpath.getEntries(), classesFolder.getFullPath(), monitor); + + MavenJdtPlugin.getDefault().getBuildpathManager().updateClasspath(project, monitor); + } + + protected String getExecutionEnvironmentId(Map<String, String> options) { + return ENVIRONMENTS.get(options.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM)); + } + + protected void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException { + addNature(project, JavaCore.NATURE_ID, monitor); + } + + protected void addCustomClasspathEntries(IJavaProject javaProject, IClasspathDescriptor classpath) + throws JavaModelException { + //Preserve existing libraries and classpath order (sort of) + // as other containers would have been added AFTER the JRE and M2 ones anyway + IClasspathEntry[] cpEntries = javaProject.getRawClasspath(); + if(cpEntries != null && cpEntries.length > 0) { + for(IClasspathEntry entry : cpEntries) { + if(IClasspathEntry.CPE_CONTAINER == entry.getEntryKind() + && !JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0)) + && !BuildPathManager.isMaven2ClasspathContainer(entry.getPath())) { + classpath.addEntry(entry); + } + } + } + } + + @SuppressWarnings("unused") + protected MavenProject getMavenProject(ProjectConfigurationRequest request, IProgressMonitor monitor) + throws CoreException { + return request.getMavenProject(); + } + + protected void invokeJavaProjectConfigurators(IClasspathDescriptor classpath, ProjectConfigurationRequest request, + final IProgressMonitor monitor) throws CoreException { + IMavenProjectFacade facade = request.getMavenProjectFacade(); + IProjectConfigurationManager configurationManager = MavenPlugin.getDefault().getProjectConfigurationManager(); + ILifecycleMapping lifecycleMapping = configurationManager.getLifecycleMapping(facade, monitor); + for(AbstractProjectConfigurator configurator : lifecycleMapping.getProjectConfigurators(facade, monitor)) { + if(configurator instanceof IJavaProjectConfigurator) { + ((IJavaProjectConfigurator) configurator).configureRawClasspath(request, classpath, monitor); + } + } + } + + private void addJREClasspathContainer(IClasspathDescriptor classpath, String environmentId) { + // remove existing JRE entry + classpath.removeEntry(new ClasspathDescriptor.EntryFilter() { + public boolean accept(IClasspathEntryDescriptor descriptor) { + return JavaRuntime.JRE_CONTAINER.equals(descriptor.getPath().segment(0)); + } + }); + + IClasspathEntry cpe; + IExecutionEnvironment executionEnvironment = getExecutionEnvironment(environmentId); + if(executionEnvironment == null) { + cpe = JavaRuntime.getDefaultJREContainerEntry(); + } else { + IPath containerPath = JavaRuntime.newJREContainerPath(executionEnvironment); + cpe = JavaCore.newContainerEntry(containerPath); + } + + classpath.addEntry(cpe); + } + + private IExecutionEnvironment getExecutionEnvironment(String environmentId) { + IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); + for(IExecutionEnvironment environment : manager.getExecutionEnvironments()) { + if(environment.getId().equals(environmentId)) { + return environment; + } + } + return null; + } + + private void addMavenClasspathContainer(IClasspathDescriptor classpath) { + // remove any old maven classpath container entries + classpath.removeEntry(new ClasspathDescriptor.EntryFilter() { + public boolean accept(IClasspathEntryDescriptor entry) { + return BuildPathManager.isMaven2ClasspathContainer(entry.getPath()); + } + }); + + // add new entry + IClasspathEntry cpe = BuildPathManager.getDefaultContainerEntry(); + classpath.addEntry(cpe); + } + + protected void addProjectSourceFolders(IClasspathDescriptor classpath, ProjectConfigurationRequest request, + MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { + IProject project = request.getProject(); + + IFolder classes = getFolder(project, mavenProject.getBuild().getOutputDirectory()); + IFolder testClasses = getFolder(project, mavenProject.getBuild().getTestOutputDirectory()); + + Util.createFolder(classes, true); + Util.createFolder(testClasses, true); + + IPath[] inclusion = new IPath[0]; + IPath[] exclusion = new IPath[0]; + + IPath[] inclusionTest = new IPath[0]; + IPath[] exclusionTest = new IPath[0]; + + for(Plugin plugin : mavenProject.getBuildPlugins()) { + if(isJavaCompilerExecution(plugin)) { + for(PluginExecution execution : plugin.getExecutions()) { + for(String goal : execution.getGoals()) { + if("compile".equals(goal)) { //$NON-NLS-1$ + try { + inclusion = toPaths(maven.getMojoParameterValue("includes", String[].class, request.getMavenSession(), //$NON-NLS-1$ + plugin, execution, goal)); + } catch(CoreException ex) { + MavenLogger.log(ex); + console.logError("Failed to determine compiler inclusions, assuming defaults"); + } + try { + exclusion = toPaths(maven.getMojoParameterValue("excludes", String[].class, request.getMavenSession(), //$NON-NLS-1$ + plugin, execution, goal)); + } catch(CoreException ex) { + MavenLogger.log(ex); + console.logError("Failed to determine compiler exclusions, assuming defaults"); + } + } else if("testCompile".equals(goal)) { //$NON-NLS-1$ + try { + inclusionTest = toPaths(maven.getMojoParameterValue("testIncludes", String[].class, //$NON-NLS-1$ + request.getMavenSession(), plugin, execution, goal)); + } catch(CoreException ex) { + MavenLogger.log(ex); + console.logError("Failed to determine compiler test inclusions, assuming defaults"); + } + try { + exclusionTest = toPaths(maven.getMojoParameterValue("testExcludes", String[].class, //$NON-NLS-1$ + request.getMavenSession(), plugin, execution, goal)); + } catch(CoreException ex) { + MavenLogger.log(ex); + console.logError("Failed to determine compiler test exclusions, assuming defaults"); + } + } + } + } + } + } + + addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(), inclusion, exclusion); + addResourceDirs(classpath, project, mavenProject.getBuild().getResources(), classes.getFullPath()); + + addSourceDirs(classpath, project, mavenProject.getTestCompileSourceRoots(), testClasses.getFullPath(), + inclusionTest, exclusionTest); + addResourceDirs(classpath, project, mavenProject.getBuild().getTestResources(), testClasses.getFullPath()); + } + + private IPath[] toPaths(String[] values) { + if(values == null) { + return new IPath[0]; + } + IPath[] paths = new IPath[values.length]; + for(int i = 0; i < values.length; i++ ) { + paths[i] = new Path(values[i]); + } + return paths; + } + + private void addSourceDirs(IClasspathDescriptor classpath, IProject project, List<String> sourceRoots, + IPath outputPath, IPath[] inclusion, IPath[] exclusion) throws CoreException { + for(String sourceRoot : sourceRoots) { + IFolder sourceFolder = getFolder(project, sourceRoot); + + if(sourceFolder != null && sourceFolder.exists() && sourceFolder.getProject().equals(project)) { + IClasspathEntryDescriptor cped = getEnclosingEntryDescriptor(classpath, sourceFolder.getFullPath()); + if (cped == null) { + console.logMessage("Adding source folder " + sourceFolder.getFullPath()); + classpath.addSourceEntry(sourceFolder.getFullPath(), outputPath, inclusion, exclusion, false); + } else { + console.logMessage("Not adding source folder " + sourceFolder.getFullPath() + " because it overlaps with " + cped.getPath()); + } + + } else { + if(sourceFolder != null) { + classpath.removeEntry(sourceFolder.getFullPath()); + } + } + } + } + + private IClasspathEntryDescriptor getEnclosingEntryDescriptor(IClasspathDescriptor classpath, IPath fullPath) { + for(IClasspathEntryDescriptor cped : classpath.getEntryDescriptors()) { + if(cped.getPath().isPrefixOf(fullPath)) { + return cped; + } + } + return null; + } + + private void addResourceDirs(IClasspathDescriptor classpath, IProject project, List<Resource> resources, + IPath outputPath) throws CoreException { + + for(Resource resource : resources) { + File resourceDirectory = new File(resource.getDirectory()); + if(resourceDirectory.exists() && resourceDirectory.isDirectory()) { + IPath relativePath = getProjectRelativePath(project, resource.getDirectory()); + IResource r = project.findMember(relativePath); + if(r == project) { + /* + * Workaround for the Java Model Exception: + * Cannot nest output folder 'xxx/src/main/resources' inside output folder 'xxx' + * when pom.xml have something like this: + * + * <build> + * <resources> + * <resource> + * <directory>${basedir}</directory> + * <targetPath>META-INF</targetPath> + * <includes> + * <include>LICENSE</include> + * </includes> + * </resource> + */ + console.logError("Skipping resource folder " + r.getFullPath()); + } else if(r != null && r.getProject().equals(project)) { + IClasspathEntryDescriptor cped = getEnclosingEntryDescriptor(classpath, r.getFullPath()); + if(cped == null) { + console.logMessage("Adding resource folder " + r.getFullPath()); + classpath.addSourceEntry(r.getFullPath(), outputPath, new IPath[0] /*inclusions*/, new IPath[] {new Path( + "**")} /*exclusion*/, false /*optional*/); + } else { + // resources and sources folders overlap. make sure JDT only processes java sources. + console.logMessage("Resources folder " + r.getFullPath() + " overlaps with sources folder " + + cped.getPath()); + cped.addInclusionPattern(new Path("**/*.java")); + } + } else { + console.logMessage("Not adding resources folder " + resourceDirectory.getAbsolutePath()); + } + } + } + } + + + protected void addJavaProjectOptions(Map<String, String> options, ProjectConfigurationRequest request, MavenProject mavenProject, + IProgressMonitor monitor) { + MavenSession mavenSession = request.getMavenSession(); + + String source = null, target = null; + + for(Plugin plugin : mavenProject.getBuildPlugins()) { + if(isJavaCompilerExecution(plugin)) { + for(PluginExecution execution : plugin.getExecutions()) { + for(String goal : execution.getGoals()) { + source = getCompilerLevel(mavenSession, plugin, execution, goal, "source", source, SOURCES); //$NON-NLS-1$ + target = getCompilerLevel(mavenSession, plugin, execution, goal, "target", target, TARGETS); //$NON-NLS-1$ + } + } + } + } + + if(source == null) { + source = DEFAULT_COMPILER_LEVEL; + console.logMessage("Could not determine source level, using default " + source); + } + + if(target == null) { + target = DEFAULT_COMPILER_LEVEL; + console.logMessage("Could not determine target level, using default " + target); + } + + options.put(JavaCore.COMPILER_SOURCE, source); + options.put(JavaCore.COMPILER_COMPLIANCE, source); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, target); + options.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, "warning"); //$NON-NLS-1$ + } + + private String getCompilerLevel(MavenSession session, Plugin plugin, PluginExecution execution, String goal, + String parameter, String source, List<String> levels) { + + int levelIdx = getLevelIndex(source, levels); + + try { + source = maven.getMojoParameterValue(parameter, String.class, session, plugin, execution, goal); + } catch(CoreException ex) { + MavenLogger.log(ex); + console.logError("Failed to determine compiler " + parameter + " setting, assuming default"); + } + + int newLevelIdx = getLevelIndex(source, levels); + + if(newLevelIdx > levelIdx) { + levelIdx = newLevelIdx; + } + + if(levelIdx < 0) { + return DEFAULT_COMPILER_LEVEL; + } + + return levels.get(levelIdx); + } + + private int getLevelIndex(String level, List<String> levels) { + return level != null ? levels.indexOf(level) : -1; + } + + private boolean isJavaCompilerExecution(Plugin plugin) { + return isJavaCompilerPlugin(plugin.getGroupId(), plugin.getArtifactId()); + } + + private boolean isJavaCompilerPlugin(String groupId, String artifactId) { + return "org.apache.maven.plugins".equals(groupId) && "maven-compiler-plugin".equals(artifactId); //$NON-NLS-1$ //$NON-NLS-2$ + } + + public void unconfigure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { + super.unconfigure(request, monitor); + removeMavenClasspathContainer(request.getProject()); + } + + private void removeMavenClasspathContainer(IProject project) throws JavaModelException { + IJavaProject javaProject = JavaCore.create(project); + if(javaProject != null) { + // remove classpatch container from JavaProject + ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); + for(IClasspathEntry entry : javaProject.getRawClasspath()) { + if(!BuildPathManager.isMaven2ClasspathContainer(entry.getPath())) { + newEntries.add(entry); + } + } + javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null); + } + } + + protected IFolder getFolder(IProject project, String absolutePath) { + return project.getFolder(getProjectRelativePath(project, absolutePath)); + } + + protected IPath getProjectRelativePath(IProject project, String absolutePath) { + File basedir = project.getLocation().toFile(); + String relative; + if(absolutePath.equals(basedir.getAbsolutePath())) { + relative = "."; //$NON-NLS-1$ + } else if(absolutePath.startsWith(basedir.getAbsolutePath())) { + relative = absolutePath.substring(basedir.getAbsolutePath().length() + 1); + } else { + relative = absolutePath; + } + return new Path(relative.replace('\\', '/')); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public boolean isSupportedExecution(MojoExecution mojoExecution) { + // Supports java compiler plugins by default + if(isJavaCompilerPlugin(mojoExecution.getGroupId(), mojoExecution.getArtifactId())) { + return true; + } + + return false; + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java new file mode 100644 index 00000000..470a2c9d --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; + +import org.apache.maven.artifact.Artifact; + +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.jdt.IClasspathDescriptor; +import org.eclipse.m2e.jdt.IClasspathEntryDescriptor; + + +/** + * This class is an attempt to encapsulate list of IClasspathEntry's and operations on the list such as "removeEntry", + * "addSourceEntry" and "addEntryAttribute". The idea is to provide JavaProjectConfigurator's classpath whiteboard they + * can use to incrementally define classpath in a consistent manner. + * + * @author igor + */ +public class ClasspathDescriptor implements IClasspathDescriptor { + + private final ArrayList<IClasspathEntryDescriptor> entries = new ArrayList<IClasspathEntryDescriptor>(); + + public ClasspathDescriptor(IJavaProject project) { + } + + /** + * @return true if classpath contains entry with specified path, false otherwise. + */ + public boolean containsPath(IPath path) { + for(IClasspathEntryDescriptor descriptor : entries) { + if(path.equals(descriptor.getPath())) { + return true; + } + } + return false; + } + + public ClasspathEntryDescriptor addSourceEntry(IPath sourcePath, IPath outputLocation, boolean generated) { + return addSourceEntry(sourcePath, // + outputLocation, // + new IPath[0] /* inclusion */, // + new IPath[0] /* exclusion */, // + generated); + } + + public List<IClasspathEntryDescriptor> removeEntry(final IPath path) { + return removeEntry(new EntryFilter() { + public boolean accept(IClasspathEntryDescriptor descriptor) { + return path.equals(descriptor.getPath()); + } + }); + } + + public List<IClasspathEntryDescriptor> removeEntry(EntryFilter filter) { + ArrayList<IClasspathEntryDescriptor> result = new ArrayList<IClasspathEntryDescriptor>(); + + Iterator<IClasspathEntryDescriptor> iter = entries.iterator(); + while(iter.hasNext()) { + IClasspathEntryDescriptor descriptor = iter.next(); + if(filter.accept(descriptor)) { + result.add(descriptor); + iter.remove(); + } + } + + return result; + } + + public ClasspathEntryDescriptor addSourceEntry(IPath sourcePath, IPath outputLocation, IPath[] inclusion, + IPath[] exclusion, boolean generated) { +// IWorkspaceRoot workspaceRoot = project.getProject().getWorkspace().getRoot(); +// +// Util.createFolder(workspaceRoot.getFolder(sourcePath), generated); + + ClasspathEntryDescriptor descriptor = new ClasspathEntryDescriptor(IClasspathEntry.CPE_SOURCE, sourcePath); + descriptor.setOutputLocation(outputLocation); + descriptor.setInclusionPatterns(inclusion); + descriptor.setExclusionPatterns(exclusion); + if(generated) { + descriptor.setClasspathAttribute(IClasspathAttribute.OPTIONAL, "true"); //$NON-NLS-1$ + } + + entries.add(descriptor); + + return descriptor; + } + + public IClasspathEntry[] getEntries() { + IClasspathEntry[] result = new IClasspathEntry[entries.size()]; + + for(int i = 0; i < entries.size(); i++ ) { + result[i] = entries.get(i).toClasspathEntry(); + } + + return result; + } + + public List<IClasspathEntryDescriptor> getEntryDescriptors() { + return entries; + } + + public ClasspathEntryDescriptor addEntry(IClasspathEntry cpe) { + ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(cpe); + entries.add(entry); + return entry; + } + + @SuppressWarnings("deprecation") + public ClasspathEntryDescriptor addProjectEntry(Artifact a, IMavenProjectFacade projectFacade) { + ClasspathEntryDescriptor entry = addProjectEntry(projectFacade.getFullPath()); + entry.setArtifactKey(new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier())); + entry.setScope(a.getScope()); + entry.setOptionalDependency(a.isOptional()); + return entry; + } + + public ClasspathEntryDescriptor addProjectEntry(IPath entryPath) { + ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(IClasspathEntry.CPE_PROJECT, entryPath); + + entries.add(entry); + + return entry; + } + + @SuppressWarnings("deprecation") + public ClasspathEntryDescriptor addLibraryEntry(Artifact artifact, IPath srcPath, IPath srcRoot, String javaDocUrl) { + ArtifactKey artifactKey = new ArtifactKey(artifact); + IPath entryPath = new Path(artifact.getFile().getAbsolutePath()); + + ClasspathEntryDescriptor entry = addLibraryEntry(entryPath); + entry.setArtifactKey(artifactKey); + + if(javaDocUrl != null) { + entry.setClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javaDocUrl); + } + + return entry; + } + + public ClasspathEntryDescriptor addLibraryEntry(IPath entryPath) { + ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(IClasspathEntry.CPE_LIBRARY, entryPath); + + entries.add(entry); + + return entry; + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java new file mode 100644 index 00000000..4262a22a --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java @@ -0,0 +1,290 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IAccessRule; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.JavaCore; + +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.jdt.BuildPathManager; +import org.eclipse.m2e.jdt.IClasspathEntryDescriptor; + + +/** + * ClasspathEntryDescriptor + * + * @author igor + */ +public class ClasspathEntryDescriptor implements IClasspathEntryDescriptor { + + private int entryKind; + + private IPath path; + + private boolean exported; + + private IPath outputLocation; + + private List<IAccessRule> accessRules = new ArrayList<IAccessRule>(); + + private LinkedHashMap<String, String> attributes = new LinkedHashMap<String, String>(); + + private IPath sourceAttachmentPath; + + private IPath sourceAttachmentRootPath; + + private LinkedHashSet<IPath> inclusionPatterns; + + private LinkedHashSet<IPath> exclusionPatterns; + + private boolean combineAccessRules; + + // maven specific attributes below + + private ArtifactKey artifactKey; + + private String scope; + + private boolean optionalDependency; + + public ClasspathEntryDescriptor(int entryKind, IPath path) { + this.entryKind = entryKind; + this.path = path; + } + + public ClasspathEntryDescriptor(IClasspathEntry entry) { + setClasspathEntry(entry); + } + + @SuppressWarnings("deprecation") + public IClasspathEntry getClasspathEntry() { + return toClasspathEntry(); + } + + public IClasspathEntry toClasspathEntry() { + Map<String, String> attributes = new LinkedHashMap<String, String>(this.attributes); + + if(artifactKey != null) { + attributes.put(BuildPathManager.GROUP_ID_ATTRIBUTE, artifactKey.getGroupId()); + attributes.put(BuildPathManager.ARTIFACT_ID_ATTRIBUTE, artifactKey.getArtifactId()); + attributes.put(BuildPathManager.VERSION_ATTRIBUTE, artifactKey.getVersion()); + if(artifactKey.getClassifier() != null) { + attributes.put(BuildPathManager.CLASSIFIER_ATTRIBUTE, artifactKey.getClassifier()); + } + } + if(scope != null) { + attributes.put(BuildPathManager.SCOPE_ATTRIBUTE, scope); + } + + IClasspathAttribute[] attributesArray = new IClasspathAttribute[attributes.size()]; + int attributeIndex = 0; + for(Map.Entry<String, String> attribute : attributes.entrySet()) { + attributesArray[attributeIndex++ ] = JavaCore.newClasspathAttribute(attribute.getKey(), attribute.getValue()); + } + + IAccessRule[] accessRulesArray = accessRules.toArray(new IAccessRule[accessRules.size()]); + IClasspathEntry entry; + switch(entryKind) { + case IClasspathEntry.CPE_CONTAINER: + entry = JavaCore.newContainerEntry(path, // + accessRulesArray, // + attributesArray, // + exported); + break; + case IClasspathEntry.CPE_LIBRARY: + entry = JavaCore.newLibraryEntry(path, // + sourceAttachmentPath, // + sourceAttachmentRootPath, // + accessRulesArray, // + attributesArray, // + exported); + break; + case IClasspathEntry.CPE_SOURCE: + entry = JavaCore.newSourceEntry(path, // + getInclusionPatterns(), // + getExclusionPatterns(), // + outputLocation, // + attributesArray); + break; + case IClasspathEntry.CPE_PROJECT: + entry = JavaCore.newProjectEntry(path, // + accessRulesArray, // + combineAccessRules, // + attributesArray, // + exported); + break; + default: + throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + entryKind); //$NON-NLS-1$ + } + return entry; + } + + public String getScope() { + return scope; + } + + /** + * @return true if this entry corresponds to an optional maven dependency, false otherwise + */ + public boolean isOptionalDependency() { + return optionalDependency; + } + + @SuppressWarnings("deprecation") + public void addClasspathAttribute(IClasspathAttribute attribute) { + setClasspathAttribute(attribute.getName(), attribute.getValue()); + } + + public void setClasspathAttribute(String name, String value) { + if(name == null) { + throw new NullPointerException(); // fail fast + } + if(value != null) { + attributes.put(name, value); + } else { + attributes.remove(name); + } + } + + public String getGroupId() { + return artifactKey != null ? artifactKey.getGroupId() : null; + } + + @SuppressWarnings("deprecation") + public void setClasspathEntry(IClasspathEntry entry) { + this.entryKind = entry.getEntryKind(); + this.path = entry.getPath(); + this.exported = entry.isExported(); + this.outputLocation = entry.getOutputLocation(); + + this.accessRules = new ArrayList<IAccessRule>(); + for(IAccessRule rule : entry.getAccessRules()) { + this.accessRules.add(rule); + } + + this.attributes = new LinkedHashMap<String, String>(); + for(IClasspathAttribute attribute : entry.getExtraAttributes()) { + attributes.put(attribute.getName(), attribute.getValue()); + } + + this.sourceAttachmentPath = entry.getSourceAttachmentPath(); + this.sourceAttachmentRootPath = entry.getSourceAttachmentRootPath(); + setInclusionPatterns(entry.getInclusionPatterns()); + setExclusionPatterns(entry.getExclusionPatterns()); + this.combineAccessRules = entry.combineAccessRules(); + } + + public String getArtifactId() { + return artifactKey != null ? artifactKey.getArtifactId() : null; + } + + public IPath getPath() { + return path; + } + + public int getEntryKind() { + return entryKind; + } + + public ArtifactKey getArtifactKey() { + return artifactKey; + } + + public void setArtifactKey(ArtifactKey artifactKey) { + this.artifactKey = artifactKey; + } + + public void setSourceAttachment(IPath srcPath, IPath srcRoot) { + this.sourceAttachmentPath = srcPath; + this.sourceAttachmentRootPath = srcRoot; + } + + public void setJavadocUrl(String javaDocUrl) { + setClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javaDocUrl); + } + + public IPath getSourceAttachmentPath() { + return sourceAttachmentPath; + } + + public IPath getSourceAttachmentRootPath() { + return sourceAttachmentRootPath; + } + + public String getJavadocUrl() { + return attributes.get(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME); + } + + public void setScope(String scope) { + this.scope = scope; + } + + public void setOptionalDependency(boolean optional) { + this.optionalDependency = optional; + } + + public void addAccessRule(IAccessRule rule) { + this.accessRules.add(rule); + } + + public void setOutputLocation(IPath outputLocation) { + this.outputLocation = outputLocation; + } + + public void setInclusionPatterns(IPath[] inclusionPatterns) { + if (inclusionPatterns!=null) { + this.inclusionPatterns = new LinkedHashSet<IPath>(Arrays.asList(inclusionPatterns)); + } else { + this.inclusionPatterns = null; + } + } + + public void addInclusionPattern(IPath pattern) { + if (inclusionPatterns == null) { + inclusionPatterns = new LinkedHashSet<IPath>(); + } + inclusionPatterns.add(pattern); + } + + public IPath[] getInclusionPatterns() { + return inclusionPatterns != null? inclusionPatterns.toArray(new IPath[inclusionPatterns.size()]) : null; + } + + public void setExclusionPatterns(IPath[] exclusionPatterns) { + if (exclusionPatterns!=null) { + this.exclusionPatterns = new LinkedHashSet<IPath>(Arrays.asList(exclusionPatterns)); + } else { + this.exclusionPatterns = null; + } + } + + public void addExclusionPattern(IPath pattern) { + if (exclusionPatterns == null) { + exclusionPatterns = new LinkedHashSet<IPath>(); + } + exclusionPatterns.add(pattern); + } + + public IPath[] getExclusionPatterns() { + return exclusionPatterns != null? exclusionPatterns.toArray(new IPath[exclusionPatterns.size()]) : null; + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java new file mode 100644 index 00000000..9b9c6a71 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.project.MavenProject; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.IProjectConfigurationManager; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; +import org.eclipse.m2e.core.project.configurator.ILifecycleMapping; +import org.eclipse.m2e.jdt.BuildPathManager; +import org.eclipse.m2e.jdt.IClasspathDescriptor; +import org.eclipse.m2e.jdt.IClasspathEntryDescriptor; +import org.eclipse.m2e.jdt.IClasspathManagerDelegate; +import org.eclipse.m2e.jdt.IJavaProjectConfigurator; + + +/** + * DefaultClasspathManagerDelegate + * + * @author igor + */ +public class DefaultClasspathManagerDelegate implements IClasspathManagerDelegate { + private final IProjectConfigurationManager configurationManager; + + private final MavenProjectManager projectManager; + + public DefaultClasspathManagerDelegate() { + this.configurationManager = MavenPlugin.getDefault().getProjectConfigurationManager(); + this.projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + } + + public void populateClasspath(final IClasspathDescriptor classpath, IMavenProjectFacade projectFacade, + final int kind, final IProgressMonitor monitor) throws CoreException { + + addClasspathEntries(classpath, projectFacade, kind, monitor); + + for(IJavaProjectConfigurator configurator : getJavaProjectConfigurators(projectFacade, monitor)) { + configurator.configureClasspath(projectFacade, classpath, monitor); + } + } + + private List<IJavaProjectConfigurator> getJavaProjectConfigurators(IMavenProjectFacade projectFacade, + final IProgressMonitor monitor) throws CoreException { + + ArrayList<IJavaProjectConfigurator> configurators = new ArrayList<IJavaProjectConfigurator>(); + + ILifecycleMapping lifecycleMapping = configurationManager.getLifecycleMapping(projectFacade, monitor); + + for(AbstractProjectConfigurator configurator : lifecycleMapping.getProjectConfigurators(projectFacade, monitor)) { + if(configurator instanceof IJavaProjectConfigurator) { + configurators.add((IJavaProjectConfigurator) configurator); + } + } + + return configurators; + } + + void addClasspathEntries(IClasspathDescriptor classpath, IMavenProjectFacade facade, int kind, + IProgressMonitor monitor) throws CoreException { + ArtifactFilter scopeFilter; + + if(BuildPathManager.CLASSPATH_RUNTIME == kind) { + // ECLIPSE-33: runtime+provided scope + // ECLIPSE-85: adding system scope + scopeFilter = new ArtifactFilter() { + public boolean include(Artifact artifact) { + return BuildPathManager.SCOPE_FILTER_RUNTIME.include(artifact) + || Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) + || Artifact.SCOPE_SYSTEM.equals(artifact.getScope()); + } + }; + } else { + // ECLIPSE-33: test scope (already includes provided) + scopeFilter = BuildPathManager.SCOPE_FILTER_TEST; + } + + MavenProject mavenProject = facade.getMavenProject(monitor); + Set<Artifact> artifacts = mavenProject.getArtifacts(); + for(Artifact a : artifacts) { + if(!scopeFilter.include(a) || !a.getArtifactHandler().isAddedToClasspath()) { + continue; + } + + // project + IMavenProjectFacade dependency = projectManager + .getMavenProject(a.getGroupId(), a.getArtifactId(), a.getVersion()); + if(dependency != null && dependency.getProject().equals(facade.getProject())) { + continue; + } + + IClasspathEntryDescriptor entry = null; + + if(dependency != null && dependency.getFullPath(a.getFile()) != null) { + entry = classpath.addProjectEntry(dependency.getFullPath()); + } else { + File artifactFile = a.getFile(); + if(artifactFile != null /*&& artifactFile.canRead()*/) { + entry = classpath.addLibraryEntry(Path.fromOSString(artifactFile.getAbsolutePath())); + } + } + + if(entry != null) { + entry.setArtifactKey(new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier())); + entry.setScope(a.getScope()); + entry.setOptionalDependency(a.isOptional()); + } + } + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JDTCompilationParticipant.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JDTCompilationParticipant.java new file mode 100644 index 00000000..f3114012 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JDTCompilationParticipant.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import java.util.Date; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.compiler.BuildContext; +import org.eclipse.jdt.core.compiler.CompilationParticipant; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.MavenConsole; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.IMavenConfiguration; +import org.eclipse.m2e.jdt.MavenJdtPlugin; + + +public class JDTCompilationParticipant extends CompilationParticipant { + + public static boolean DEBUG = MavenPlugin.getDefault().isDebugging() + & Boolean.parseBoolean(Platform.getDebugOption(MavenJdtPlugin.PLUGIN_ID + "/debug/compilationParticipant")); //$NON-NLS-1$ + + @Override + public synchronized void cleanStarting(IJavaProject project) { + if(DEBUG) { + System.out.println("\nRequested clean for " + project.getProject() //$NON-NLS-1$ + + " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$ + } + + MavenPlugin plugin = MavenPlugin.getDefault(); + IMavenConfiguration configuration = MavenPlugin.getDefault().getMavenConfiguration(); + if (configuration.isDebugOutput()) { + MavenConsole console = plugin.getConsole(); + console.logMessage("Maven compilation participant: clean starting"); + } + + super.cleanStarting(project); + + try { + plugin.getMavenProjectManager().requestFullMavenBuild(project.getProject()); + } catch(CoreException ex) { + MavenLogger.log("Exception requesting full Maven build", ex); + } + } + + public void buildStarting(BuildContext[] files, boolean isBatch) { + } + + // 3.4 + public void buildFinished(IJavaProject project) { + } + + public boolean isActive(IJavaProject project) { + return true; + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JarLifecycleMapping.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JarLifecycleMapping.java new file mode 100644 index 00000000..0659161d --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JarLifecycleMapping.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2008 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import org.eclipse.m2e.core.project.configurator.DefaultLifecycleMapping; + +/** + * @author igor + */ +public class JarLifecycleMapping extends DefaultLifecycleMapping { + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaElementsAdapterFactory.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaElementsAdapterFactory.java new file mode 100644 index 00000000..bed3b4da --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaElementsAdapterFactory.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; +import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer.RequiredProjectWrapper; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.jdt.MavenJdtPlugin; + + +/** + * Adapter factory for Java elements + * + * @author Igor Fedorenko + * @author Eugene Kuleshov + */ +@SuppressWarnings({"unchecked", "restriction"}) +public class JavaElementsAdapterFactory implements IAdapterFactory { + + private static final Class[] ADAPTER_LIST = new Class[] {ArtifactKey.class, IPath.class, IMavenProjectFacade.class}; + + public Class[] getAdapterList() { + return ADAPTER_LIST; + } + + public Object getAdapter(Object adaptableObject, Class adapterType) { + if(adapterType == ArtifactKey.class) { + if(adaptableObject instanceof IPackageFragmentRoot) { + IPackageFragmentRoot fragment = (IPackageFragmentRoot) adaptableObject; + IProject project = fragment.getJavaProject().getProject(); + if(project.isAccessible() && fragment.isArchive()) { + try { + return MavenJdtPlugin.getDefault().getBuildpathManager().findArtifact(project, fragment.getPath()); + } catch(CoreException ex) { + MavenLogger.log(ex); + MavenPlugin.getDefault().getConsole().logError("Can't find artifact for " + fragment); + return null; + } + } + + } else if(adaptableObject instanceof RequiredProjectWrapper) { + IMavenProjectFacade projectFacade = getProjectFacade(adaptableObject); + if(projectFacade!=null) { + return projectFacade.getArtifactKey(); + } + + } else if(adaptableObject instanceof IJavaProject) { + return ((IJavaProject) adaptableObject).getProject().getAdapter(ArtifactKey.class); + + } + + } else if(adapterType == IPath.class) { + if(adaptableObject instanceof IJavaElement) { + IResource resource = ((IJavaElement) adaptableObject).getResource(); + if(resource != null) { + return resource.getLocation(); + } + } + + } else if(adapterType == IMavenProjectFacade.class) { + if(adaptableObject instanceof IJavaElement) { + IProject project = ((IJavaElement) adaptableObject).getJavaProject().getProject(); + IMavenProjectFacade projectFacade = getProjectFacade(project); + if(projectFacade != null) { + return projectFacade; + } + + } else if(adaptableObject instanceof RequiredProjectWrapper) { + ClassPathContainer container = ((RequiredProjectWrapper) adaptableObject).getParentClassPathContainer(); + IProject project = container.getJavaProject().getProject(); + IMavenProjectFacade projectFacade = getProjectFacade(project); + if(projectFacade != null) { + return projectFacade; + } + } + } + + return null; + } + + private IMavenProjectFacade getProjectFacade(Object adaptableObject) { + RequiredProjectWrapper wrapper = (RequiredProjectWrapper) adaptableObject; + return getProjectFacade(wrapper.getProject().getProject()); + } + + private IMavenProjectFacade getProjectFacade(IProject project) { + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + return projectManager.create(project, new NullProgressMonitor()); + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConfigurator.java new file mode 100644 index 00000000..81d0633f --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/JavaProjectConfigurator.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +/** + * DefaultJavaConfigurator + * + * @author igor + */ +public class JavaProjectConfigurator extends AbstractJavaProjectConfigurator { + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainer.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainer.java new file mode 100644 index 00000000..62ceedfe --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainer.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import java.io.Serializable; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IClasspathEntry; + +/** + * Maven classpath container + */ +public class MavenClasspathContainer implements IClasspathContainer, Serializable { + private static final long serialVersionUID = -5976726121300869771L; + + private final IClasspathEntry[] entries; + private final IPath path; + + public MavenClasspathContainer(IPath path, IClasspathEntry[] entries) { + this.path = path; + this.entries = entries; + } + + public String getDescription() { + return Messages.MavenClasspathContainer_description; + } + + public int getKind() { + return IClasspathContainer.K_APPLICATION; + } + + public synchronized IClasspathEntry[] getClasspathEntries() { + return entries; + } + + public IPath getPath() { + return path; + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerInitializer.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerInitializer.java new file mode 100644 index 00000000..b6ae8fe3 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerInitializer.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.ClasspathContainerInitializer; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.IMavenConfiguration; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.core.project.MavenUpdateRequest; +import org.eclipse.m2e.jdt.BuildPathManager; +import org.eclipse.m2e.jdt.MavenJdtPlugin; + + +/** + * MavenClasspathContainerInitializer + * + * @author Eugene Kuleshov + */ +public class MavenClasspathContainerInitializer extends ClasspathContainerInitializer { + + public void initialize(IPath containerPath, IJavaProject project) { + if(BuildPathManager.isMaven2ClasspathContainer(containerPath)) { + try { + IClasspathContainer mavenContainer = getBuildPathManager().getSavedContainer(project.getProject()); + if(mavenContainer != null) { + JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, + new IClasspathContainer[] {mavenContainer}, new NullProgressMonitor()); + return; + } + } catch(CoreException ex) { + MavenLogger.log("Exception initializing classpath container " + containerPath.toString(), ex); + } + + // force refresh if can't read persisted state + IMavenConfiguration configuration = MavenPlugin.getDefault().getMavenConfiguration(); + MavenUpdateRequest request = new MavenUpdateRequest(project.getProject(), configuration.isOffline(), false); + getMavenProjectManager().refresh(request); + } + } + + public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) { + return true; + } + + public void requestClasspathContainerUpdate(IPath containerPath, final IJavaProject project, + final IClasspathContainer containerSuggestion) { + // one job per request. assumption that users are not going to change hundreds of containers simultaneously. + new Job(Messages.MavenClasspathContainerInitializer_job_name) { + protected IStatus run(IProgressMonitor monitor) { + try { + getBuildPathManager().persistAttachedSourcesAndJavadoc(project, containerSuggestion, monitor); + } catch(CoreException ex) { + MavenLogger.log(ex); + return new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, Messages.MavenClasspathContainerInitializer_error_cannot_persist, ex); + } + return Status.OK_STATUS; + } + }.schedule(); + } + + BuildPathManager getBuildPathManager() { + return MavenJdtPlugin.getDefault().getBuildpathManager(); + } + + MavenProjectManager getMavenProjectManager() { + return MavenPlugin.getDefault().getMavenProjectManager(); + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerSaveHelper.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerSaveHelper.java new file mode 100644 index 00000000..c82fb60a --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathContainerSaveHelper.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IAccessRule; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.JavaCore; + + +/** + * BuildPath save helper + * + * @author Eugene Kuleshov + */ +public class MavenClasspathContainerSaveHelper { + + public IClasspathContainer readContainer(InputStream input) throws IOException, ClassNotFoundException { + ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(input)) { + { + enableResolveObject(true); + } + protected Object resolveObject(Object o) throws IOException { + if(o instanceof ProjectEntryReplace) { + return ((ProjectEntryReplace) o).getEntry(); + } else if(o instanceof LibraryEntryReplace) { + return ((LibraryEntryReplace) o).getEntry(); + } else if(o instanceof ClasspathAttributeReplace) { + return ((ClasspathAttributeReplace) o).getAttribute(); + } else if(o instanceof AccessRuleReplace) { + return ((AccessRuleReplace) o).getAccessRule(); + } else if(o instanceof PathReplace) { + return ((PathReplace) o).getPath(); + } + return super.resolveObject(o); + } + }; + return (IClasspathContainer) is.readObject(); + } + + public void writeContainer(IClasspathContainer container, OutputStream output) throws IOException { + ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(output)) { + { + enableReplaceObject(true); + } + + protected Object replaceObject(Object o) throws IOException { + if(o instanceof IClasspathEntry) { + IClasspathEntry e = (IClasspathEntry) o; + if(e.getEntryKind()==IClasspathEntry.CPE_PROJECT) { + return new ProjectEntryReplace(e); + } else if(e.getEntryKind()==IClasspathEntry.CPE_LIBRARY) { + return new LibraryEntryReplace(e); + } + } else if(o instanceof IClasspathAttribute) { + return new ClasspathAttributeReplace((IClasspathAttribute) o); + } else if(o instanceof IAccessRule) { + return new AccessRuleReplace((IAccessRule) o); + } else if(o instanceof IPath) { + return new PathReplace((IPath) o); + } + return super.replaceObject(o); + } + }; + os.writeObject(container); + os.flush(); + } + + /** + * A library IClasspathEntry replacement used for object serialization + */ + static final class LibraryEntryReplace implements Serializable { + private static final long serialVersionUID = 3901667379326978799L; + + private final IPath path; + private final IPath sourceAttachmentPath; + private final IPath sourceAttachmentRootPath; + private final IClasspathAttribute[] extraAttributes; + private final boolean exported; + private final IAccessRule[] accessRules; + + LibraryEntryReplace(IClasspathEntry entry) { + this.path = entry.getPath(); + this.sourceAttachmentPath = entry.getSourceAttachmentPath(); + this.sourceAttachmentRootPath = entry.getSourceAttachmentRootPath(); + this.accessRules = entry.getAccessRules(); + this.extraAttributes = entry.getExtraAttributes(); + this.exported = entry.isExported(); + } + + IClasspathEntry getEntry() { + return JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, // + accessRules, extraAttributes, exported); + } + } + + /** + * A project IClasspathEntry replacement used for object serialization + */ + static final class ProjectEntryReplace implements Serializable { + private static final long serialVersionUID = -2397483865904288762L; + + private final IPath path; + private final IClasspathAttribute[] extraAttributes; + private final IAccessRule[] accessRules; + private final boolean exported; + private final boolean combineAccessRules; + + ProjectEntryReplace(IClasspathEntry entry) { + this.path = entry.getPath(); + this.accessRules = entry.getAccessRules(); + this.extraAttributes = entry.getExtraAttributes(); + this.exported = entry.isExported(); + this.combineAccessRules = entry.combineAccessRules(); + } + + IClasspathEntry getEntry() { + return JavaCore.newProjectEntry(path, accessRules, // + combineAccessRules, extraAttributes, exported); + } + } + + /** + * An IClasspathAttribute replacement used for object serialization + */ + static final class ClasspathAttributeReplace implements Serializable { + private static final long serialVersionUID = 6370039352012628029L; + + private final String name; + private final String value; + + ClasspathAttributeReplace(IClasspathAttribute attribute) { + this.name = attribute.getName(); + this.value = attribute.getValue(); + } + + IClasspathAttribute getAttribute() { + return JavaCore.newClasspathAttribute(name, value); + } + } + + /** + * An IAccessRule replacement used for object serialization + */ + static final class AccessRuleReplace implements Serializable { + private static final long serialVersionUID = 7315582893941374715L; + + private final IPath pattern; + private final int kind; + + AccessRuleReplace(IAccessRule accessRule) { + pattern = accessRule.getPattern(); + kind = accessRule.getKind(); + } + + IAccessRule getAccessRule() { + return JavaCore.newAccessRule(pattern, kind); + } + } + + /** + * An IPath replacement used for object serialization + */ + static final class PathReplace implements Serializable { + private static final long serialVersionUID = -2361259525684491181L; + + private final String path; + + PathReplace(IPath path) { + this.path = path.toPortableString(); + } + + IPath getPath() { + return Path.fromPortableString(path); + } + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathVariableInitializer.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathVariableInitializer.java new file mode 100644 index 00000000..fe976056 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathVariableInitializer.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + + +import org.eclipse.jdt.core.ClasspathVariableInitializer; + +import org.eclipse.m2e.jdt.MavenJdtPlugin; + +/** + * Maven classpath variable initializer is used to handle M2_REPO variable. + * + * @author Eugene Kuleshov + */ +public class MavenClasspathVariableInitializer extends ClasspathVariableInitializer { + + public MavenClasspathVariableInitializer() { + } + + public void initialize(String variable) { + MavenJdtPlugin.getDefault().getBuildpathManager().setupVariables(); + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenJdtImages.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenJdtImages.java new file mode 100644 index 00000000..fb741584 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenJdtImages.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.jdt.MavenJdtPlugin; + + +/** + * @author Eugene Kuleshov + */ +public class MavenJdtImages { + + // object images + + // public static final Image IMG_CLEAR = createImage("clear.gif"); + + // descriptors + + public static final ImageDescriptor JAVA_DOC = create("javadoc.gif"); //$NON-NLS-1$ + + + private static ImageDescriptor create(String key) { + try { + ImageRegistry imageRegistry = getImageRegistry(); + if(imageRegistry != null) { + ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(key); + if(imageDescriptor==null) { + imageDescriptor = createDescriptor(key); + imageRegistry.put(key, imageDescriptor); + } + return imageDescriptor; + } + } catch(Exception ex) { + MavenLogger.log(key, ex); + } + return null; + } + +// private static Image createImage(String key) { +// create(key); +// ImageRegistry imageRegistry = getImageRegistry(); +// return imageRegistry == null ? null : imageRegistry.get(key); +// } + + private static ImageRegistry getImageRegistry() { + MavenJdtPlugin plugin = MavenJdtPlugin.getDefault(); + return plugin == null ? null : plugin.getImageRegistry(); + } + + private static ImageDescriptor createDescriptor(String image) { + return AbstractUIPlugin.imageDescriptorFromPlugin(IMavenConstants.PLUGIN_ID, "icons/" + image); //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/Messages.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/Messages.java new file mode 100644 index 00000000..8a2d3e2f --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/Messages.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal; + +import org.eclipse.osgi.util.NLS; + + +/** + * Messages + * + * @author mkleint + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.m2e.jdt.internal.messages"; //$NON-NLS-1$ + + public static String AbstractJavaProjectConfigurator_task_name; + + public static String BuildPathManager_monitor_setting_cp; + + public static String DownloadSourcesJob_job_download; + + public static String GenericJavaProjectConfigurator_subtask; + + public static String GenericJavaProjectConfigurator_subtask_refreshing; + + public static String MavenClasspathContainer_description; + + public static String MavenClasspathContainerInitializer_error_cannot_persist; + + public static String MavenClasspathContainerInitializer_job_name; + + public static String MavenClasspathContainerPage_control_desc; + + public static String MavenClasspathContainerPage_control_title; + + public static String MavenClasspathContainerPage_link; + + public static String MavenClasspathContainerPage_title; + + public static String MavenDependencyResolver_additional_info; + + public static String MavenDependencyResolver_error_message; + + public static String MavenDependencyResolver_error_message2; + + public static String MavenDependencyResolver_error_message3; + + public static String MavenDependencyResolver_error_message4; + + public static String MavenDependencyResolver_error_message5; + + public static String MavenDependencyResolver_error_message6; + + public static String MavenDependencyResolver_error_message7; + + public static String MavenDependencyResolver_error_title; + + public static String MavenDependencyResolver_proposal_search; + + public static String MavenDependencyResolver_searchDialog_title; + + public static String MavenJdtMenuCreator_action_downloadJavadoc; + + public static String MavenJdtMenuCreator_action_downloadSources; + + public static String MavenJdtMenuCreator_action_javadoc; + + public static String MavenJdtMenuCreator_action_materialize1; + + public static String MavenJdtMenuCreator_action_materializeMany; + + public static String MavenJdtMenuCreator_action_open_issue; + + public static String MavenJdtMenuCreator_action_openCI; + + public static String MavenJdtMenuCreator_action_openJavadoc; + + public static String MavenJdtMenuCreator_action_openPom; + + public static String MavenJdtMenuCreator_action_openProject; + + public static String MavenJdtMenuCreator_action_sources; + + public static String MavenJdtMenuCreator_axtion_openScm; + + public static String MavenJdtPlugin_job_name; + + public static String MavenQueryParticipant_job_name; + + public static String MavenQueryParticipant_searchDialog_title; + + public static String MavenRuntimeClasspathProvider_error_unsupported; + public static String OpenJavaDocAction_error_download; + + public static String OpenJavaDocAction_error_message; + + public static String OpenJavaDocAction_error_title; + + public static String OpenJavaDocAction_info_title; + + public static String OpenJavaDocAction_job_open_javadoc; + + public static String OpenJavaDocAction_message1; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/actions/DownloadSourcesAction.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/actions/DownloadSourcesAction.java new file mode 100644 index 00000000..e3316183 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/actions/DownloadSourcesAction.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal.actions; + +import java.util.Iterator; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkingSet; + +import org.eclipse.m2e.jdt.BuildPathManager; +import org.eclipse.m2e.jdt.MavenJdtPlugin; + + + +public class DownloadSourcesAction implements IObjectActionDelegate { + + public static final String ID_SOURCES = "org.eclipse.m2e.downloadSourcesAction"; //$NON-NLS-1$ + + public static final String ID_JAVADOC = "org.eclipse.m2e.downloadJavaDocAction"; //$NON-NLS-1$ + + private IStructuredSelection selection; + + private String id; + + public DownloadSourcesAction(String id) { + this.id = id; + } + + public void run(IAction action) { + if(selection != null) { + BuildPathManager buildpathManager = MavenJdtPlugin.getDefault().getBuildpathManager(); + for(Iterator<?> it = selection.iterator(); it.hasNext();) { + Object element = it.next(); + if(element instanceof IProject) { + IProject project = (IProject) element; + buildpathManager.scheduleDownload(project, ID_SOURCES.equals(id), !ID_SOURCES.equals(id)); + } else if(element instanceof IPackageFragmentRoot) { + IPackageFragmentRoot fragment = (IPackageFragmentRoot) element; + buildpathManager.scheduleDownload(fragment, ID_SOURCES.equals(id), !ID_SOURCES.equals(id)); + } else if(element instanceof IWorkingSet) { + IWorkingSet workingSet = (IWorkingSet) element; + for(IAdaptable adaptable : workingSet.getElements()) { + IProject project = (IProject) adaptable.getAdapter(IProject.class); + buildpathManager.scheduleDownload(project, ID_SOURCES.equals(id), !ID_SOURCES.equals(id)); + } + } + } + } + } + + public void selectionChanged(IAction action, ISelection selection) { + if(selection instanceof IStructuredSelection) { + this.selection = (IStructuredSelection) selection; + } else { + this.selection = null; + } + } + + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/actions/OpenJavaDocAction.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/actions/OpenJavaDocAction.java new file mode 100644 index 00000000..43877de7 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/actions/OpenJavaDocAction.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal.actions; + +import java.io.File; +import java.net.URL; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionDelegate; +import org.eclipse.ui.browser.IWebBrowser; +import org.eclipse.ui.browser.IWorkbenchBrowserSupport; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.actions.SelectionUtil; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.jdt.internal.Messages; + +/** + * Open JavaDoc action + * + * @author Eugene Kuleshov + */ +public class OpenJavaDocAction extends ActionDelegate { + + public static final String ID = "org.eclipse.m2e.openJavaDocAction"; //$NON-NLS-1$ + + private IStructuredSelection selection; + + public void selectionChanged(IAction action, ISelection selection) { + if(selection instanceof IStructuredSelection) { + this.selection = (IStructuredSelection) selection; + } else { + this.selection = null; + } + } + + public void run(IAction action) { + if(selection != null) { + try { + final ArtifactKey ak = SelectionUtil.getArtifactKey(this.selection.getFirstElement()); + if(ak == null) { + openDialog(Messages.OpenJavaDocAction_message1); + return; + } + + new Job(NLS.bind(Messages.OpenJavaDocAction_job_open_javadoc,ak)) { + protected IStatus run(IProgressMonitor monitor) { + openJavaDoc(ak.getGroupId(), ak.getArtifactId(), ak.getVersion(), monitor); + return Status.OK_STATUS; + } + }.schedule(); + + } catch(CoreException ex) { + MavenLogger.log(ex); + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + MessageDialog.openInformation(Display.getDefault().getActiveShell(), // + Messages.OpenJavaDocAction_error_title, Messages.OpenJavaDocAction_error_message); + } + }); + } + } + } + + protected void openJavaDoc(String groupId, String artifactId, String version, IProgressMonitor monitor) { + final String name = groupId + ":" + artifactId + ":" + version + ":javadoc"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + try { + IMaven maven = MavenPlugin.getDefault().getMaven(); + + List<ArtifactRepository> artifactRepositories = maven.getArtifactRepositories(); + + Artifact artifact = maven.resolve(groupId, artifactId, version, "javadoc", "javadoc", artifactRepositories, monitor); //$NON-NLS-1$ //$NON-NLS-2$ + + final File file = artifact.getFile(); + if(file == null) { + openDialog(NLS.bind(Messages.OpenJavaDocAction_error_download, name)); + return; + } + + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + try { + String url = "jar:" + file.toURI().toString() + "!/index.html"; //$NON-NLS-1$ //$NON-NLS-2$ + URL helpUrl = PlatformUI.getWorkbench().getHelpSystem().resolve(url, true); + + IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport(); + IWebBrowser browser = browserSupport.createBrowser(IWorkbenchBrowserSupport.NAVIGATION_BAR, // + name, name, name); + browser.openURL(helpUrl); + } catch(PartInitException ex) { + MavenLogger.log(ex); + } + } + }); + + } catch(CoreException ex) { + MavenLogger.log("Can't download JavaDoc for " + name, ex); + openDialog(NLS.bind(Messages.OpenJavaDocAction_error_download,name)); + // TODO search index and offer to select other version + } + + } + + private static void openDialog(final String msg) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + MessageDialog.openInformation(Display.getDefault().getActiveShell(), // + Messages.OpenJavaDocAction_info_title, msg); + } + }); + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenLaunchConfigurationListener.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenLaunchConfigurationListener.java new file mode 100644 index 00000000..71690b46 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenLaunchConfigurationListener.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal.launch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationListener; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; +import org.eclipse.jdt.launching.JavaRuntime; + +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.project.IMavenProjectChangedListener; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; + +public class MavenLaunchConfigurationListener implements ILaunchConfigurationListener, IMavenProjectChangedListener { + + public void launchConfigurationAdded(ILaunchConfiguration configuration) { + updateLaunchConfiguration(configuration); + } + + public void launchConfigurationChanged(ILaunchConfiguration configuration) { + updateLaunchConfiguration(configuration); + } + + public void launchConfigurationRemoved(ILaunchConfiguration configuration) { + // do nothing + } + + private void updateLaunchConfiguration(ILaunchConfiguration configuration) { + try { + if (!MavenRuntimeClasspathProvider.isSupportedType(configuration.getType().getIdentifier())) { + return; + } + if (configuration.getAttributes().containsKey(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER)) { + return; + } + IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); + if (javaProject != null && javaProject.getProject().hasNature(IMavenConstants.NATURE_ID)) { + MavenRuntimeClasspathProvider.enable(configuration); + } + } catch(CoreException ex) { + MavenLogger.log(ex); + } + } + + public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) { + for (MavenProjectChangedEvent event : events) { + try { + switch (event.getKind()) { + case MavenProjectChangedEvent.KIND_ADDED: + MavenRuntimeClasspathProvider.enable(event.getMavenProject().getProject()); + break; + case MavenProjectChangedEvent.KIND_REMOVED: + MavenRuntimeClasspathProvider.disable(event.getOldMavenProject().getProject()); + break; + default: + break; + } + } catch (Exception e) { + MavenLogger.log("Could not update launch configuration", e); + } + } + } +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java new file mode 100644 index 00000000..b65adf58 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java @@ -0,0 +1,359 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal.launch; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; +import org.eclipse.jdt.launching.IRuntimeClasspathEntry; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.StandardClasspathProvider; +import org.eclipse.osgi.util.NLS; + +import org.apache.maven.model.Build; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.core.project.ResolverConfiguration; +import org.eclipse.m2e.jdt.BuildPathManager; +import org.eclipse.m2e.jdt.MavenJdtPlugin; +import org.eclipse.m2e.jdt.internal.Messages; + + +public class MavenRuntimeClasspathProvider extends StandardClasspathProvider { + + public static final String MAVEN_SOURCEPATH_PROVIDER = "org.eclipse.m2e.launchconfig.sourcepathProvider"; //$NON-NLS-1$ + + public static final String MAVEN_CLASSPATH_PROVIDER = "org.eclipse.m2e.launchconfig.classpathProvider"; //$NON-NLS-1$ + + private static final String TESTS_PROJECT_CLASSIFIER = "tests"; //$NON-NLS-1$ + + private static final String THIS_PROJECT_CLASSIFIER = ""; //$NON-NLS-1$ + + public static final String JDT_JUNIT_TEST = "org.eclipse.jdt.junit.launchconfig"; //$NON-NLS-1$ + + public static final String JDT_JAVA_APPLICATION = "org.eclipse.jdt.launching.localJavaApplication"; //$NON-NLS-1$ + + public static final String JDT_TESTNG_TEST = "org.testng.eclipse.launchconfig"; //$NON-NLS-1$ + + private static final Set<String> supportedTypes = new HashSet<String>(); + static { + // not exactly nice, but works with eclipse 3.2, 3.3 and 3.4M3 + supportedTypes.add(MavenRuntimeClasspathProvider.JDT_JAVA_APPLICATION); + supportedTypes.add(MavenRuntimeClasspathProvider.JDT_JUNIT_TEST); + supportedTypes.add(MavenRuntimeClasspathProvider.JDT_TESTNG_TEST); + } + + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + + public IRuntimeClasspathEntry[] computeUnresolvedClasspath(final ILaunchConfiguration configuration) throws CoreException { + boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); + if (useDefault) { + IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); + IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(configuration); + IRuntimeClasspathEntry projectEntry = JavaRuntime.newProjectRuntimeClasspathEntry(javaProject); + IRuntimeClasspathEntry mavenEntry = JavaRuntime.newRuntimeContainerClasspathEntry(new Path(BuildPathManager.CONTAINER_ID), IRuntimeClasspathEntry.USER_CLASSES); + + if(jreEntry == null) { + return new IRuntimeClasspathEntry[] {projectEntry, mavenEntry}; + } + + return new IRuntimeClasspathEntry[] {jreEntry, projectEntry, mavenEntry}; + } + + return recoverRuntimePath(configuration, IJavaLaunchConfigurationConstants.ATTR_CLASSPATH); + } + + public IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration) + throws CoreException { + IProgressMonitor monitor = new NullProgressMonitor(); // XXX + int scope = getArtifactScope(configuration); + Set<IRuntimeClasspathEntry> all = new LinkedHashSet<IRuntimeClasspathEntry>(entries.length); + for(IRuntimeClasspathEntry entry : entries) { + if (entry.getType() == IRuntimeClasspathEntry.CONTAINER && BuildPathManager.isMaven2ClasspathContainer(entry.getPath())) { + addMavenClasspathEntries(all, entry, configuration, scope, monitor); + } else if (entry.getType() == IRuntimeClasspathEntry.PROJECT) { + IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); + if (javaProject.getPath().equals(entry.getPath())) { + addProjectEntries(all, entry.getPath(), scope, THIS_PROJECT_CLASSIFIER, configuration, monitor); + } else { + addStandardClasspathEntries(all, entry, configuration); + } + } else { + addStandardClasspathEntries(all, entry, configuration); + } + } + return all.toArray(new IRuntimeClasspathEntry[all.size()]); + } + + private void addStandardClasspathEntries(Set<IRuntimeClasspathEntry> all, IRuntimeClasspathEntry entry, ILaunchConfiguration configuration) + throws CoreException + { + IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveRuntimeClasspathEntry(entry, configuration); + for (int j = 0; j < resolved.length; j++) { + all.add(resolved[j]); + } + } + + private void addMavenClasspathEntries(Set<IRuntimeClasspathEntry> resolved, IRuntimeClasspathEntry runtimeClasspathEntry, + ILaunchConfiguration configuration, int scope, IProgressMonitor monitor) throws CoreException + { + IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); + MavenJdtPlugin plugin = MavenJdtPlugin.getDefault(); + BuildPathManager buildpathManager = plugin.getBuildpathManager(); + IClasspathEntry[] cp = buildpathManager.getClasspath(javaProject.getProject(), scope, false, new NullProgressMonitor()); + for(IClasspathEntry entry : cp) { + switch (entry.getEntryKind()) { + case IClasspathEntry.CPE_PROJECT: + addProjectEntries(resolved, entry.getPath(), scope, getArtifactClassifier(entry), configuration, monitor); + break; + case IClasspathEntry.CPE_LIBRARY: + resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath())); + break; +// case IClasspathEntry.CPE_SOURCE: +// resolved.add(newSourceClasspathEntry(javaProject, cp[i])); +// break; + } + } + } + + protected int getArtifactScope(ILaunchConfiguration configuration) throws CoreException { + String typeid = configuration.getType().getAttribute("id"); //$NON-NLS-1$ + if (JDT_JAVA_APPLICATION.equals(typeid)) { + IResource[] resources = configuration.getMappedResources(); + + // MNGECLIPSE-530: NPE starting openarchitecture workflow + if (resources == null || resources.length == 0) { + return BuildPathManager.CLASSPATH_RUNTIME; + } + + // ECLIPSE-33: applications from test sources should use test scope + final Set<IPath> testSources = new HashSet<IPath>(); + IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); + IMavenProjectFacade facade = projectManager.create(javaProject.getProject(), new NullProgressMonitor()); + if (facade == null) { + return BuildPathManager.CLASSPATH_RUNTIME; + } + + testSources.addAll(Arrays.asList(facade.getTestCompileSourceLocations())); + + for (int i = 0; i < resources.length; i++) { + for (IPath testPath : testSources) { + if (testPath.isPrefixOf(resources[i].getProjectRelativePath())) { + return BuildPathManager.CLASSPATH_TEST; + } + } + } + return BuildPathManager.CLASSPATH_RUNTIME; + } else if(JDT_JUNIT_TEST.equals(typeid) || JDT_TESTNG_TEST.equals(typeid)) { + return BuildPathManager.CLASSPATH_TEST; + } else { + throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, + NLS.bind(Messages.MavenRuntimeClasspathProvider_error_unsupported, typeid), null)); + } + } + + protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier, ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject project = root.getProject(path.segment(0)); + + IMavenProjectFacade projectFacade = projectManager.create(project, monitor); + if(projectFacade == null) { + return; + } + + ResolverConfiguration configuration = projectFacade.getResolverConfiguration(); + if (configuration == null) { + return; + } + + final Set<IPath> allClasses = new LinkedHashSet<IPath>(); + final Set<IPath> allTestClasses = new LinkedHashSet<IPath>(); + + Build build = projectFacade.getMavenProject(monitor).getBuild(); + allClasses.add(projectFacade.getProjectRelativePath(build.getOutputDirectory())); + allTestClasses.add(projectFacade.getProjectRelativePath(build.getTestOutputDirectory())); + + IJavaProject javaProject = JavaCore.create(project); + + boolean projectResolved = false; + for(IClasspathEntry entry : javaProject.getRawClasspath()) { + IRuntimeClasspathEntry rce = null; + switch (entry.getEntryKind()) { + case IClasspathEntry.CPE_SOURCE: + if (!projectResolved) { + if (BuildPathManager.CLASSPATH_TEST == scope && isTestClassifier(classifier)) { + // ECLIPSE-19: test classes come infront on the rest + addFolders(resolved, project, allTestClasses); + } + if (isMainClassifier(classifier)) { + addFolders(resolved, project, allClasses); + } + projectResolved = true; + } + break; + case IClasspathEntry.CPE_CONTAINER: + IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); + if (container != null && !BuildPathManager.isMaven2ClasspathContainer(entry.getPath())) { + switch (container.getKind()) { + case IClasspathContainer.K_APPLICATION: + rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.USER_CLASSES, javaProject); + break; +// case IClasspathContainer.K_DEFAULT_SYSTEM: +// unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.STANDARD_CLASSES, javaProject)); +// break; +// case IClasspathContainer.K_SYSTEM: +// unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.BOOTSTRAP_CLASSES, javaProject)); +// break; + } + } + break; + case IClasspathEntry.CPE_LIBRARY: + rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); + break; + case IClasspathEntry.CPE_VARIABLE: + if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { + rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); + } + break; + case IClasspathEntry.CPE_PROJECT: + IProject res = root.getProject(entry.getPath().segment(0)); + if (res != null) { + IJavaProject otherProject = JavaCore.create(res); + if (otherProject != null) { + rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject); + } + } + break; + default: + break; + } + if (rce != null) { + addStandardClasspathEntries(resolved, rce, launchConfiguration); + } + } + } + + private boolean isMainClassifier(String classifier) { + return THIS_PROJECT_CLASSIFIER.equals(classifier) // main project + || classifier == null; // default classifier + } + + private boolean isTestClassifier(String classifier) { + return THIS_PROJECT_CLASSIFIER.equals(classifier) // main project + || TESTS_PROJECT_CLASSIFIER.equals(classifier) // tests classifier + || classifier != null; // unknown classifier + } + + private void addFolders(Set<IRuntimeClasspathEntry> resolved, IProject project, Set<IPath> folders) { + for(IPath folder : folders) { + IResource member = project.findMember(folder); // only returns existing members + if(member instanceof IFolder) { // must exist and be a folder + resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(member.getFullPath())); + } + } + } + + public static boolean isSupportedType(String id) { + return supportedTypes.contains(id); + } + + public static void enable(ILaunchConfiguration config) throws CoreException { + if (config instanceof ILaunchConfigurationWorkingCopy) { + enable((ILaunchConfigurationWorkingCopy) config); + } else { + ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); + enable(wc); + wc.doSave(); + } + } + + private static void enable(ILaunchConfigurationWorkingCopy wc) { + wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, MAVEN_CLASSPATH_PROVIDER); + wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, MAVEN_SOURCEPATH_PROVIDER); + } + + public static void disable(ILaunchConfiguration config) throws CoreException { + ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); + wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, (String) null); + wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, (String) null); + wc.doSave(); + } + + private static String getArtifactClassifier(IClasspathEntry entry) { + IClasspathAttribute[] attributes = entry.getExtraAttributes(); + for(IClasspathAttribute attribute : attributes) { + if(BuildPathManager.CLASSIFIER_ATTRIBUTE.equals(attribute.getName())) { + return attribute.getValue(); + } + } + return null; + } + + public static void enable(IProject project) throws CoreException { + for(ILaunchConfiguration config : getLaunchConfiguration(project)) { + if(isSupportedType(config.getType().getIdentifier())) { + enable(config); + } + } + } + + public static void disable(IProject project) throws CoreException { + for(ILaunchConfiguration config : getLaunchConfiguration(project)) { + if(isSupportedType(config.getType().getIdentifier())) { + disable(config); + } + } + } + + private static List<ILaunchConfiguration> getLaunchConfiguration(IProject project) throws CoreException { + ArrayList<ILaunchConfiguration> result = new ArrayList<ILaunchConfiguration>(); + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfiguration[] configurations = launchManager.getLaunchConfigurations(); + for(ILaunchConfiguration config : configurations) { + String projectName = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null); + if (project.getName().equals(projectName)) { + result.add(config); + } + } + return result; + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java new file mode 100644 index 00000000..d13145ab --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal.launch; + +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; +import org.eclipse.jdt.launching.IRuntimeClasspathEntry; +import org.eclipse.jdt.launching.JavaRuntime; + + + +public class MavenSourcePathProvider extends MavenRuntimeClasspathProvider { + + public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException { + boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_SOURCE_PATH, true); + if(useDefault) { + // the default source lookup path is the same as the classpath + return super.computeUnresolvedClasspath(configuration); + } + // recover persisted source path + return recoverRuntimePath(configuration, IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH); + } + + @Override + protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier, ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject project = root.getProject(path.segment(0)); + IJavaProject javaProject = JavaCore.create(project); + resolved.add(JavaRuntime.newProjectRuntimeClasspathEntry(javaProject)); + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/messages.properties b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/messages.properties new file mode 100644 index 00000000..799b0b3d --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/messages.properties @@ -0,0 +1,45 @@ +AbstractJavaProjectConfigurator_task_name=Configuring java project +BuildPathManager_monitor_setting_cp=Setting classpath containers +DownloadSourcesJob_job_download=Download sources and javadoc +GenericJavaProjectConfigurator_subtask=reading {0} +GenericJavaProjectConfigurator_subtask_refreshing=refreshing +MavenClasspathContainer_description=Maven Dependencies +MavenClasspathContainerInitializer_error_cannot_persist=Can't persist classpath container +MavenClasspathContainerInitializer_job_name=Persist classpath container changes +MavenClasspathContainerPage_control_desc=Set the dependency resolver configuration +MavenClasspathContainerPage_control_title=Maven Managed Dependencies +MavenClasspathContainerPage_link=Use <a href="\#maven">Maven Project settings</a> to configure Maven dependency resolution +MavenClasspathContainerPage_title=Maven Dependencies +MavenDependencyResolver_additional_info=Resolve dependencies from Maven repositories +MavenDependencyResolver_error_message=Unable to retrieve corresponding resource +MavenDependencyResolver_error_message2=Project does not have pom.xml +MavenDependencyResolver_error_message3=Unable to read project natures +MavenDependencyResolver_error_message4=Unable to read Maven project +MavenDependencyResolver_error_message5=Unable to locate pom.xml for {0} +MavenDependencyResolver_error_message6=Unable to locate pom.xml for {0} +MavenDependencyResolver_error_message7=Unable to add import statement for {0} +MavenDependencyResolver_error_title=Add Dependency +MavenDependencyResolver_proposal_search=Search dependency for {0} +MavenDependencyResolver_searchDialog_title=Search in Maven repositories +MavenJdtMenuCreator_action_downloadJavadoc=Download JavaDoc +MavenJdtMenuCreator_action_downloadSources=Download Sources +MavenJdtMenuCreator_action_javadoc=Download JavaDoc +MavenJdtMenuCreator_action_materialize1=Import Project +MavenJdtMenuCreator_action_materializeMany=Import Projects +MavenJdtMenuCreator_action_open_issue=Open Issue Tracker +MavenJdtMenuCreator_action_openCI=Open Continuous Integration +MavenJdtMenuCreator_action_openJavadoc=Open JavaDoc +MavenJdtMenuCreator_action_openPom=Open POM +MavenJdtMenuCreator_action_openProject=Open Project Page +MavenJdtMenuCreator_action_sources=Download Sources +MavenJdtMenuCreator_axtion_openScm=Open Source Control +MavenJdtPlugin_job_name=Building... +MavenQueryParticipant_job_name=Opening {0} +MavenQueryParticipant_searchDialog_title=Open Type from Maven +MavenRuntimeClasspathProvider_error_unsupported=Unsupported launch configuration type {0} +OpenJavaDocAction_error_download=Can't download JavaDoc for {0} +OpenJavaDocAction_error_message=Unable to read Maven project +OpenJavaDocAction_error_title=Open JavaDoc +OpenJavaDocAction_info_title=Show JavaDoc +OpenJavaDocAction_job_open_javadoc=Opening JavaDoc for {0} +OpenJavaDocAction_message1=Unable to identify Maven artifact diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ui/MavenClasspathContainerPage.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ui/MavenClasspathContainerPage.java new file mode 100644 index 00000000..e199d703 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ui/MavenClasspathContainerPage.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal.ui; + +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; +import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.dialogs.PreferencesUtil; + +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.jdt.internal.Messages; + + +/** + * MavenClasspathContainerPage + * + * @author Eugene Kuleshov + */ +public class MavenClasspathContainerPage extends WizardPage implements IClasspathContainerPage, + IClasspathContainerPageExtension { + + IJavaProject javaProject; + + private IClasspathEntry containerEntry; + + public MavenClasspathContainerPage() { + super(Messages.MavenClasspathContainerPage_title); + } + + // IClasspathContainerPageExtension + + public void initialize(IJavaProject javaProject, IClasspathEntry[] currentEntries) { + this.javaProject = javaProject; + // this.currentEntries = currentEntries; + } + + // IClasspathContainerPage + + public IClasspathEntry getSelection() { + return this.containerEntry; + } + + public void setSelection(IClasspathEntry containerEntry) { + this.containerEntry = containerEntry; + } + + public void createControl(Composite parent) { + setTitle(Messages.MavenClasspathContainerPage_control_title); + setDescription(Messages.MavenClasspathContainerPage_control_desc); + + + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout()); + setControl(composite); + + Link link = new Link(composite, SWT.NONE); + link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + link.setText(Messages.MavenClasspathContainerPage_link); + link.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // IWorkbenchPreferenceContainer container= (IWorkbenchPreferenceContainer) getContainer(); + // container.openPage(MavenProjectPreferencePage.ID, javaProject.getProject()); + + PreferencesUtil.createPropertyDialogOn(getShell(), javaProject.getProject(), // + IMavenConstants.PREFERENCE_PAGE_ID, new String[] {IMavenConstants.PREFERENCE_PAGE_ID}, null).open(); + } + }); + } + + public boolean finish() { + return true; + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ui/MavenJdtMenuCreator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ui/MavenJdtMenuCreator.java new file mode 100644 index 00000000..c4c83e63 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ui/MavenJdtMenuCreator.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.jdt.internal.ui; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.actions.AbstractMavenMenuCreator; +import org.eclipse.m2e.core.actions.MaterializeAction; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.actions.OpenUrlAction; +import org.eclipse.m2e.core.actions.SelectionUtil; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.jdt.internal.MavenJdtImages; +import org.eclipse.m2e.jdt.internal.Messages; +import org.eclipse.m2e.jdt.internal.actions.DownloadSourcesAction; +import org.eclipse.m2e.jdt.internal.actions.OpenJavaDocAction; + + +/** + * Maven menu creator for JDT + * + * @author Eugene Kuleshov + */ +public class MavenJdtMenuCreator extends AbstractMavenMenuCreator { + + private static final String ID_SOURCES = "org.eclipse.m2e.downloadSourcesAction"; //$NON-NLS-1$ + + private static final String ID_JAVADOC = "org.eclipse.m2e.downloadJavaDocAction"; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.m2e.internal.actions.AbstractMavenMenuCreator#createMenu(org.eclipse.jface.action.MenuManager) + */ + public void createMenu(IMenuManager mgr) { + int selectionType = SelectionUtil.getSelectionType(selection); + if(selectionType == SelectionUtil.UNSUPPORTED) { + return; + } + + if(selectionType == SelectionUtil.PROJECT_WITH_NATURE) { + mgr.appendToGroup(UPDATE, getAction(new DownloadSourcesAction(ID_JAVADOC), // + DownloadSourcesAction.ID_JAVADOC, Messages.MavenJdtMenuCreator_action_javadoc)); + mgr.appendToGroup(UPDATE, getAction(new DownloadSourcesAction(ID_SOURCES), // + DownloadSourcesAction.ID_SOURCES, Messages.MavenJdtMenuCreator_action_sources)); + } + + if(selectionType == SelectionUtil.JAR_FILE) { + boolean isProject = false; + if(selection.size() == 1) { + ArtifactKey key = SelectionUtil.getType(selection.getFirstElement(), ArtifactKey.class); + if(key != null) { + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + IMavenProjectFacade mavenProject = null; + mavenProject = projectManager.getMavenProject( // + key.getGroupId(), key.getArtifactId(), key.getVersion()); + if(mavenProject!=null) { + isProject = true; + } + } + } + + if(!isProject) { + mgr.appendToGroup(UPDATE, getAction(new DownloadSourcesAction(ID_SOURCES), // + DownloadSourcesAction.ID_SOURCES, Messages.MavenJdtMenuCreator_action_sources)); + mgr.appendToGroup(UPDATE, getAction(new DownloadSourcesAction(ID_JAVADOC), // + DownloadSourcesAction.ID_JAVADOC, Messages.MavenJdtMenuCreator_action_javadoc)); + mgr.prependToGroup(OPEN, new Separator()); + } + + mgr.appendToGroup(OPEN, getAction(new OpenPomAction(), OpenPomAction.ID, Messages.MavenJdtMenuCreator_action_openPom)); + mgr.appendToGroup(OPEN, getAction(new OpenUrlAction(OpenUrlAction.ID_PROJECT), // + OpenUrlAction.ID_PROJECT, Messages.MavenJdtMenuCreator_action_openProject)); + mgr.appendToGroup(OPEN, getAction(new OpenUrlAction(OpenUrlAction.ID_ISSUES), // + OpenUrlAction.ID_ISSUES, Messages.MavenJdtMenuCreator_action_open_issue)); + mgr.appendToGroup(OPEN, getAction(new OpenUrlAction(OpenUrlAction.ID_SCM), // + OpenUrlAction.ID_SCM, Messages.MavenJdtMenuCreator_axtion_openScm)); + mgr.appendToGroup(OPEN, getAction(new OpenUrlAction(OpenUrlAction.ID_CI), // + OpenUrlAction.ID_CI, Messages.MavenJdtMenuCreator_action_openCI)); + mgr.appendToGroup(OPEN, getAction(new OpenJavaDocAction(), // + OpenJavaDocAction.ID, Messages.MavenJdtMenuCreator_action_openJavadoc, MavenJdtImages.JAVA_DOC)); + + if(!isProject) { + mgr.prependToGroup(IMPORT, new Separator()); + mgr.appendToGroup(IMPORT, getAction(new MaterializeAction(), // + MaterializeAction.ID, // + selection.size() == 1 ? Messages.MavenJdtMenuCreator_action_materialize1 : Messages.MavenJdtMenuCreator_action_materializeMany, "icons/import_m2_project.gif")); //$NON-NLS-3$ + } + } + + if(selectionType == SelectionUtil.WORKING_SET) { + mgr.appendToGroup(UPDATE, getAction(new DownloadSourcesAction(ID_SOURCES), // + DownloadSourcesAction.ID_SOURCES, Messages.MavenJdtMenuCreator_action_downloadSources)); + mgr.appendToGroup(UPDATE, getAction(new DownloadSourcesAction(ID_JAVADOC), // + DownloadSourcesAction.ID_JAVADOC, Messages.MavenJdtMenuCreator_action_downloadJavadoc)); + } + } + +} diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/ui/internal/filter/MavenModuleFilter.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/ui/internal/filter/MavenModuleFilter.java new file mode 100644 index 00000000..c75dd1c5 --- /dev/null +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/ui/internal/filter/MavenModuleFilter.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.ui.internal.filter; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +import org.apache.maven.project.MavenProject; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; + +/** + * MavenModuleFilter + * + * @author Eugene Kuleshov + */ +public class MavenModuleFilter extends ViewerFilter { + + public boolean select(Viewer viewer, Object parentElement, Object element) { + if(element instanceof IFolder) { + IFolder folder = (IFolder) element; + IProject project = folder.getProject(); + try { + if(project.hasNature(IMavenConstants.NATURE_ID)) { + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + + IMavenProjectFacade projectFacade = projectManager.create(project, null); + if(projectFacade != null) { + // XXX implement corner cases + // modules have ".." in the path + // modules have more then one segment in the path + // modules not imported in workspace + MavenProject mavenProject = projectFacade.getMavenProject(null); + IPath folderPath = folder.getFullPath(); + + // workspace-relative path sans project name + String folderName = folderPath.removeFirstSegments(1).toPortableString(); + + if(mavenProject.getModules().contains(folderName)) { + return false; + } + } + } + } catch(CoreException ex) { + MavenLogger.log(ex); + } + + } + return true; + } + +} + |