Merge branch 'stable-2.15' * stable-2.15: Upgrade bazlets to latest stable-2.15 to build with 2.15.7 API Upgrade bazlets to latest stable-2.14 to build with 2.14.17 API Upgrade bazlets to latest stable-2.15 to build with 2.15.6 API WORKSPACE: Make commented out local_path line spaces indent consistent Upgrade bazlets to latest stable-2.14 to build with 2.14.16 API Fix classpath generation for Eclipse project Align Eclipse compiler settings with core Gerrit's bazlets: Replace native.git_repository with skylark rule Upgrade bazlets to latest stable-2.15 to build with 2.15.5 API Update bazlets to latest stable-2.14 to build with 2.14.15 API Update bazlets to latest stable-2.15 and adjust to 2.15.4 API Update bazlets to latest stable-2.14 to build with 2.14.14 API Migrate (i.e. move) `tools/bazel.rc` to `.bazelrc` Update bazlets to latest stable-2.14 to build with 2.14.13 API Format all build files with buildifier Format all Java files with google-java-format Format all build files with buildifier Update bazlets to latest stable-2.14 and adjust to 2.14.12 API Format all Java files with google-java-format Update bazlets to latest revision on stable-2.15 Update bazlets to latest stable-2.14 Minor documentation fixes Remove mention of draft changes from the documentation Update bazlets to latest stable-2.15 to use 2.15.1 API Format all Java files with google-java-format Bazel: Switch to using release plugin API Change equality comparison for consistency Handle sub-patch versioning Handle changes in refs/meta Handle file comment Fix inline comment position Use latest bazlets Change-Id: Ie926ed8b9f4a9d1338973d1cadde05614dc868c5
diff --git a/tools/bazel.rc b/.bazelrc similarity index 100% rename from tools/bazel.rc rename to .bazelrc
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 602b029..40e022d 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,12 +1,25 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.8 +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.problem.APILeak=warning org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=ignore +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -14,11 +27,12 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.fieldHiding=warning org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning @@ -27,32 +41,48 @@ org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning +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=private org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=enabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning +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.missingJavadocTagDescription=return_tag +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore @@ -60,287 +90,37 @@ org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled +org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=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=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedImport=warning org.eclipse.jdt.core.compiler.problem.unusedLabel=warning org.eclipse.jdt.core.compiler.problem.unusedLocal=warning org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=warning org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.processAnnotations=enabled org.eclipse.jdt.core.compiler.source=1.8 -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=16 -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=16 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16 -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=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=0 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=0 -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=0 -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=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=true -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=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false -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=80 -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=4 -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=do not 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=do not 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=do not 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=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=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=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=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=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.join_lines_in_comments=true -org.eclipse.jdt.core.formatter.join_wrapped_lines=true -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=true -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -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=3 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=false -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
diff --git a/WORKSPACE b/WORKSPACE index 4c89bfa..6758bff 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -3,27 +3,27 @@ load("//:bazlets.bzl", "load_bazlets") load_bazlets( - commit = "b7514d03a7798905ff1513295b46620e57b8f386", - # local_path = "/home/<user>/projects/bazlets", + commit = "b54eaed487d37188120da6933b97c571519954ca", + #local_path = "/home/<user>/projects/bazlets", ) #Snapshot Plugin API -load( - "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", - "gerrit_api_maven_local", -) - -# Load snapshot Plugin API -gerrit_api_maven_local() - -# Release Plugin API #load( -# "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", -# "gerrit_api", +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", #) +# Load snapshot Plugin API +#gerrit_api_maven_local() + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + # Load release Plugin API -#gerrit_api() +gerrit_api() load( "@com_googlesource_gerrit_bazlets//:gerrit_gwt.bzl",
diff --git a/bazlets.bzl b/bazlets.bzl index e14e488..f089af4 100644 --- a/bazlets.bzl +++ b/bazlets.bzl
@@ -1,17 +1,18 @@ +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + NAME = "com_googlesource_gerrit_bazlets" def load_bazlets( - commit, - local_path = None - ): - if not local_path: - native.git_repository( - name = NAME, - remote = "https://gerrit.googlesource.com/bazlets", - commit = commit, - ) - else: - native.local_repository( - name = NAME, - path = local_path, - ) + commit, + local_path = None): + if not local_path: + git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java b/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java index 07e5d8f..feb5da6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/AccountUtil.java
@@ -33,18 +33,17 @@ import com.google.gerrit.server.account.AuthRequest; import com.google.gerrit.server.account.CreateAccount; import com.google.gerrit.server.account.VersionedAuthorizedKeys; +import com.google.gerrit.server.account.externalids.ExternalId; import com.google.gerrit.server.config.AuthConfig; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Singleton; - -import org.eclipse.jgit.errors.ConfigInvalidException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.util.List; import java.util.Objects; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Singleton class AccountUtil { @@ -76,12 +75,13 @@ } Account.Id resolveUser(GerritApi api, AccountInfo acc) - throws NoSuchAccountException, IOException, OrmException, - RestApiException, ConfigInvalidException { + throws NoSuchAccountException, IOException, OrmException, RestApiException, + ConfigInvalidException { if (acc.username == null) { - throw new NoSuchAccountException(String.format( - "User %s <%s> (%s) doesn't have a username and cannot be looked up.", - acc.name, acc.email, acc._accountId)); + throw new NoSuchAccountException( + String.format( + "User %s <%s> (%s) doesn't have a username and cannot be looked up.", + acc.name, acc.email, acc._accountId)); } AccountState a = accountCache.getByUsername(acc.username); @@ -103,19 +103,19 @@ } } if (!Objects.equals(a.getAccount().getPreferredEmail(), acc.email)) { - log.warn(String.format( - "Email mismatch for user %s: expected %s but found %s", - acc.username, acc.email, a.getAccount().getPreferredEmail())); + log.warn( + String.format( + "Email mismatch for user %s: expected %s but found %s", + acc.username, acc.email, a.getAccount().getPreferredEmail())); } return a.getAccount().getId(); } - private Account.Id createAccountByLdapAndAddSshKeys(GerritApi api, - AccountInfo acc) throws NoSuchAccountException, IOException, OrmException, - RestApiException, ConfigInvalidException { - if (!acc.username.matches(Account.USER_NAME_PATTERN)) { - throw new NoSuchAccountException(String.format("User %s not found", - acc.username)); + private Account.Id createAccountByLdapAndAddSshKeys(GerritApi api, AccountInfo acc) + throws NoSuchAccountException, IOException, OrmException, RestApiException, + ConfigInvalidException { + if (!ExternalId.isValidUsername(acc.username)) { + throw new NoSuchAccountException(String.format("User %s not found", acc.username)); } try { @@ -130,8 +130,7 @@ } private void addSshKeys(GerritApi api, AccountInfo acc) - throws BadRequestException, IOException, OrmException, - ConfigInvalidException { + throws BadRequestException, IOException, OrmException, ConfigInvalidException { List<SshKeyInfo> sshKeys = api.getSshKeys(acc.username); AccountState a = accountCache.getByUsername(acc.username); for (SshKeyInfo sshKeyInfo : sshKeys) { @@ -153,8 +152,7 @@ input.name = acc.name; AccountInfo accInfo = - createAccountFactory.create(username) - .apply(TopLevelResource.INSTANCE, input).value(); + createAccountFactory.create(username).apply(TopLevelResource.INSTANCE, input).value(); log.info(String.format("Local user '%s' created", username)); Account.Id userId = new Account.Id(accInfo._accountId);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java index 267925f..ac8bf2d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java
@@ -33,15 +33,13 @@ import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; - -import org.eclipse.jgit.errors.ConfigInvalidException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; class AddApprovalsStep { @@ -49,8 +47,7 @@ AddApprovalsStep create(Change change, ChangeInfo changeInfo, boolean resume); } - private static final Logger log = LoggerFactory - .getLogger(ReplayInlineCommentsStep.class); + private static final Logger log = LoggerFactory.getLogger(ReplayInlineCommentsStep.class); private final AccountUtil accountUtil; private final ChangeUpdate.Factory updateFactory; @@ -62,7 +59,8 @@ private final boolean resume; @Inject - public AddApprovalsStep(AccountUtil accountUtil, + public AddApprovalsStep( + AccountUtil accountUtil, ChangeUpdate.Factory updateFactory, ReviewDb db, IdentifiedUser.GenericFactory genericUserFactory, @@ -80,12 +78,11 @@ this.resume = resume; } - void add(GerritApi api) throws OrmException, NoSuchChangeException, - IOException, NoSuchAccountException, RestApiException, - ConfigInvalidException { + void add(GerritApi api) + throws OrmException, NoSuchChangeException, IOException, NoSuchAccountException, + RestApiException, ConfigInvalidException { if (resume) { - db.patchSetApprovals().delete( - db.patchSetApprovals().byChange(change.getId())); + db.patchSetApprovals().delete(db.patchSetApprovals().byChange(change.getId())); } List<PatchSetApproval> approvals = new ArrayList<>(); @@ -97,20 +94,25 @@ Account.Id user = accountUtil.resolveUser(api, a); ChangeData cd = changeDataFactory.create(db, change); LabelType labelType = cd.getLabelTypes().byLabel(labelName); - if(labelType == null) { - log.warn(String.format("Label '%s' not found in target system." - + " This label was referenced by an approval provided from '%s'" - + " for change '%s'." - + " This approval will be skipped. In order to import this" - + " approval configure the missing label and resume the import" - + " with the force option." - , labelName, a.username, changeInfo.id)); + if (labelType == null) { + log.warn( + String.format( + "Label '%s' not found in target system." + + " This label was referenced by an approval provided from '%s'" + + " for change '%s'." + + " This approval will be skipped. In order to import this" + + " approval configure the missing label and resume the import" + + " with the force option.", + labelName, a.username, changeInfo.id)); continue; } short shortValue = a.value != null ? a.value.shortValue() : 0; - approvals.add(new PatchSetApproval(new PatchSetApproval.Key(change - .currentPatchSetId(), user, labelType.getLabelId()), shortValue, - MoreObjects.firstNonNull(a.date, TimeUtil.nowTs()))); + approvals.add( + new PatchSetApproval( + new PatchSetApproval.Key( + change.currentPatchSetId(), user, labelType.getLabelId()), + shortValue, + MoreObjects.firstNonNull(a.date, TimeUtil.nowTs()))); ChangeUpdate update = updateFactory.create(cd.notes(), genericUserFactory.create(user)); if (shortValue != 0) { update.putApproval(labelName, shortValue);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java index 676c063..213d2d4 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/AddHashtagsStep.java
@@ -24,31 +24,28 @@ import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.change.ChangeTriplet; import com.google.gerrit.server.change.SetHashtagsOp; +import com.google.gerrit.server.notedb.ChangeNotes; +import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.update.BatchUpdate; import com.google.gerrit.server.update.UpdateException; -import com.google.gerrit.server.project.ChangeControl; -import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.assistedinject.Assisted; - +import java.util.HashSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; - class AddHashtagsStep { interface Factory { AddHashtagsStep create(Change change, ChangeInfo changeInfo, boolean resume); } - private static final Logger log = LoggerFactory - .getLogger(AddHashtagsStep.class); + private static final Logger log = LoggerFactory.getLogger(AddHashtagsStep.class); private final CurrentUser currentUser; - private final ChangeControl.GenericFactory changeControlFactory; + private final ChangeNotes.Factory changeNotesFactory; private final Change change; private final ChangeInfo changeInfo; private final boolean resume; @@ -57,8 +54,9 @@ private final SetHashtagsOp.Factory hashtagsFactory; @Inject - AddHashtagsStep(CurrentUser currentUser, - ChangeControl.GenericFactory changeControlFactory, + AddHashtagsStep( + CurrentUser currentUser, + ChangeNotes.Factory changeNotesFactory, Provider<ReviewDb> db, BatchUpdate.Factory batchUpdateFactory, SetHashtagsOp.Factory hashtagsFactory, @@ -66,7 +64,7 @@ @Assisted ChangeInfo changeInfo, @Assisted boolean resume) { this.currentUser = currentUser; - this.changeControlFactory = changeControlFactory; + this.changeNotesFactory = changeNotesFactory; this.db = db; this.batchUpdateFactory = batchUpdateFactory; this.hashtagsFactory = hashtagsFactory; @@ -75,38 +73,41 @@ this.resume = resume; } - void add() throws IllegalArgumentException, OrmException, - NoSuchChangeException, UpdateException, RestApiException { - ChangeControl ctrl = - changeControlFactory.controlFor(db.get(), change, currentUser); + void add() + throws IllegalArgumentException, OrmException, NoSuchChangeException, UpdateException, + RestApiException { + + ChangeNotes notes = changeNotesFactory.createChecked(db.get(), change); try { if (resume) { HashtagsInput input = new HashtagsInput(); - input.remove = ctrl.getNotes().load().getHashtags(); - try (BatchUpdate bu = batchUpdateFactory.create(db.get(), - change.getProject(), currentUser, TimeUtil.nowTs())) { - SetHashtagsOp op = hashtagsFactory.create(input); - bu.addOp(change.getId(), op); - bu.execute(); + input.remove = notes.load().getHashtags(); + try (BatchUpdate bu = + batchUpdateFactory.create( + db.get(), change.getProject(), currentUser, TimeUtil.nowTs())) { + SetHashtagsOp op = hashtagsFactory.create(input); + bu.addOp(change.getId(), op); + bu.execute(); } } HashtagsInput input = new HashtagsInput(); input.add = new HashSet<>(changeInfo.hashtags); - try (BatchUpdate bu = batchUpdateFactory.create(db.get(), - change.getProject(), currentUser, TimeUtil.nowTs())) { - SetHashtagsOp op = hashtagsFactory.create(input); - bu.addOp(change.getId(), op); - bu.execute(); + try (BatchUpdate bu = + batchUpdateFactory.create(db.get(), change.getProject(), currentUser, TimeUtil.nowTs())) { + SetHashtagsOp op = hashtagsFactory.create(input); + bu.addOp(change.getId(), op); + bu.execute(); } } catch (AuthException e) { - log.warn(String.format( - "Hashtags cannot be set on change %s because the importing" - + " user %s doesn't have permissions to edit hashtags" - + " (e.g. assign the 'Edit Hashtags' global capability" - + " and resume the import with the force option).", - ChangeTriplet.format(change), currentUser.getUserName())); + log.warn( + String.format( + "Hashtags cannot be set on change %s because the importing" + + " user %s doesn't have permissions to edit hashtags" + + " (e.g. assign the 'Edit Hashtags' global capability" + + " and resume the import with the force option).", + ChangeTriplet.format(change), currentUser.getUserName())); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImport.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImport.java index f5cabb9..731ec1c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImport.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImport.java
@@ -33,39 +33,32 @@ import com.google.gerrit.server.project.ProjectResource; import com.google.inject.Inject; import com.google.inject.Provider; - import com.googlesource.gerrit.plugins.importer.CompleteProjectImport.Input; - +import java.io.File; +import java.io.IOException; +import java.util.Map; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.internal.storage.file.LockFile; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; -import java.io.File; -import java.io.IOException; -import java.util.Map; - @RequiresCapability(ImportCapability.ID) class CompleteProjectImport implements RestModifyView<ImportProjectResource, Input> { - public static class Input { - } + public static class Input {} private final ProjectsCollection projects; private final GitRepositoryManager repoManager; @Inject - CompleteProjectImport( - ProjectsCollection projects, - GitRepositoryManager repoManager) { + CompleteProjectImport(ProjectsCollection projects, GitRepositoryManager repoManager) { this.projects = projects; this.repoManager = repoManager; } @Override public Response<?> apply(ImportProjectResource rsrc, Input input) - throws ResourceConflictException, RepositoryNotFoundException, - IOException { + throws ResourceConflictException, RepositoryNotFoundException, IOException { LockFile lock = lockForDelete(rsrc.getName()); try { deleteImportRefs(rsrc.getName()); @@ -76,16 +69,14 @@ } } - private LockFile lockForDelete(Project.NameKey project) - throws ResourceConflictException { + private LockFile lockForDelete(Project.NameKey project) throws ResourceConflictException { File importStatus = projects.FS_LAYOUT.getImportStatusFile(project.get()); LockFile lockFile = new LockFile(importStatus); try { if (lockFile.lock()) { return lockFile; } - throw new ResourceConflictException( - "project is being imported from another session"); + throw new ResourceConflictException("project is being imported from another session"); } catch (IOException e) { throw new ResourceConflictException("failed to lock project for delete"); } @@ -94,8 +85,7 @@ private void deleteImportRefs(Project.NameKey project) throws RepositoryNotFoundException, IOException { try (Repository repo = repoManager.openRepository(project)) { - Map<String, Ref> refs = repo.getRefDatabase().getRefs( - ConfigureRepositoryStep.R_IMPORTS); + Map<String, Ref> refs = repo.getRefDatabase().getRefs(ConfigureRepositoryStep.R_IMPORTS); for (Ref ref : refs.values()) { RefUpdate ru = repo.updateRef(ref.getName()); ru.setForceUpdate(true); @@ -115,15 +105,15 @@ case REJECTED_MISSING_OBJECT: case REJECTED_OTHER_REASON: default: - throw new IOException(String.format( - "Failed to delete %s, RefUpdate.Result = %s", ref, result)); + throw new IOException( + String.format("Failed to delete %s, RefUpdate.Result = %s", ref, result)); } } } } - public static class OnProjects implements - RestModifyView<ProjectResource, Input>, UiAction<ProjectResource> { + public static class OnProjects + implements RestModifyView<ProjectResource, Input>, UiAction<ProjectResource> { private final ProjectsCollection projectsCollection; private final CompleteProjectImport completeProjectImport; private final Provider<CurrentUser> currentUserProvider; @@ -131,7 +121,8 @@ private final PermissionBackend permissionBackend; @Inject - public OnProjects(ProjectsCollection projectsCollection, + public OnProjects( + ProjectsCollection projectsCollection, CompleteProjectImport completeProjectImport, Provider<CurrentUser> currentUserProvider, @PluginName String pluginName, @@ -145,11 +136,10 @@ @Override public Response<?> apply(ProjectResource rsrc, Input input) - throws ResourceNotFoundException, ResourceConflictException, - RepositoryNotFoundException, IOException { + throws ResourceNotFoundException, ResourceConflictException, RepositoryNotFoundException, + IOException { ImportProjectResource projectResource = - projectsCollection.parse(new ConfigResource(), - IdString.fromDecoded(rsrc.getName())); + projectsCollection.parse(new ConfigResource(), IdString.fromDecoded(rsrc.getName())); return completeProjectImport.apply(projectResource, input); } @@ -158,16 +148,18 @@ UiAction.Description desc = new UiAction.Description(); try { - ImportProjectResource importRsrc = projectsCollection.parse(new ConfigResource(), - IdString.fromDecoded(rsrc.getName())); + ImportProjectResource importRsrc = + projectsCollection.parse(new ConfigResource(), IdString.fromDecoded(rsrc.getName())); if (importRsrc.getInfo().from != null) { desc.setLabel("Complete Import...") - .setTitle("Complete the project import." - + " After completion, resume is not possible anymore."); + .setTitle( + "Complete the project import." + + " After completion, resume is not possible anymore."); } else { desc.setLabel("Complete Copy...") - .setTitle("Complete the project copy." - + " After completion, resume is not possible anymore."); + .setTitle( + "Complete the project copy." + + " After completion, resume is not possible anymore."); } desc.setVisible(canCompleteImport(rsrc)); } catch (IOException | ResourceNotFoundException e) { @@ -178,10 +170,11 @@ } private boolean canCompleteImport(ProjectResource rsrc) { - return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) || - (permissionBackend.user(currentUserProvider).testOrFalse( - new PluginPermission(pluginName, ImportCapability.ID)) - && rsrc.getControl().isOwner()); + return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) + || (permissionBackend + .user(currentUserProvider) + .testOrFalse(new PluginPermission(pluginName, ImportCapability.ID)) + && rsrc.getControl().isOwner()); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImportCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImportCommand.java index 02ff97f..161c3bc 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImportCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CompleteProjectImportCommand.java
@@ -19,29 +19,27 @@ import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; import com.google.inject.Inject; - +import java.io.IOException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.kohsuke.args4j.Argument; -import java.io.IOException; - @RequiresCapability(ImportCapability.ID) @CommandMetaData(name = "complete-project", description = "Completes project import") class CompleteProjectImportCommand extends SshCommand { - @Argument(index = 0, required = true, metaVar = "NAME", + @Argument( + index = 0, + required = true, + metaVar = "NAME", usage = "name of the project in target system") private String project; - @Inject - private CompleteProjectImport completeProjectImport; + @Inject private CompleteProjectImport completeProjectImport; - @Inject - private ProjectsCollection projects; + @Inject private ProjectsCollection projects; @Override - protected void run() throws UnloggedFailure, RepositoryNotFoundException, - IOException { + protected void run() throws UnloggedFailure, RepositoryNotFoundException, IOException { try { ImportProjectResource rsrc = projects.parse(project); completeProjectImport.apply(rsrc, new CompleteProjectImport.Input());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureProjectStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureProjectStep.java index 9497262..0d26d31 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureProjectStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureProjectStep.java
@@ -24,10 +24,8 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; - -import org.eclipse.jgit.lib.ProgressMonitor; - import java.io.IOException; +import org.eclipse.jgit.lib.ProgressMonitor; @Singleton class ConfigureProjectStep {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureRepositoryStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureRepositoryStep.java index aca47c3..8b199ca 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureRepositoryStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ConfigureRepositoryStep.java
@@ -21,15 +21,13 @@ import com.google.gerrit.server.config.SitePaths; import com.google.inject.Inject; import com.google.inject.Singleton; - +import java.io.IOException; +import java.nio.file.Path; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; -import java.io.IOException; -import java.nio.file.Path; - @Singleton class ConfigureRepositoryStep { @@ -38,9 +36,7 @@ private final Path gitDir; @Inject - ConfigureRepositoryStep( - SitePaths site, - @GerritServerConfig Config cfg) { + ConfigureRepositoryStep(SitePaths site, @GerritServerConfig Config cfg) { this.gitDir = site.resolve(cfg.getString("gerrit", null, "basePath")); } @@ -49,13 +45,10 @@ pm.beginTask("Configure repository", 1); StoredConfig config = repo.getConfig(); if (originUrl != null) { - config.setString("remote", "origin", "url", originUrl - .concat("/a/") - .concat(name.get())); + config.setString("remote", "origin", "url", originUrl.concat("/a/").concat(name.get())); } else { - config.setString("remote", "origin", "url", - this.gitDir.resolve(name.get() + ".git").toString()); - + config.setString( + "remote", "origin", "url", this.gitDir.resolve(name.get() + ".git").toString()); } config.setString("remote", "origin", "fetch", "+refs/*:" + R_IMPORTS + "*"); config.setString("http", null, "sslVerify", Boolean.FALSE.toString());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java index 7d9f712..d4ea7b5 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProject.java
@@ -28,28 +28,25 @@ import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.config.ConfigResource; -import com.google.gerrit.server.update.UpdateException; +import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.permissions.PermissionBackend; import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.ProjectResource; +import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.validators.ValidationException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; - import com.googlesource.gerrit.plugins.importer.CopyProject.Input; - -import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.errors.ConfigInvalidException; - import java.io.IOException; import java.io.PrintWriter; import java.io.Writer; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.errors.ConfigInvalidException; @RequiresCapability(CopyProjectCapability.ID) -class CopyProject implements RestModifyView<ProjectResource, Input>, - UiAction<ProjectResource> { +class CopyProject implements RestModifyView<ProjectResource, Input>, UiAction<ProjectResource> { public static class Input { public String name; } @@ -74,9 +71,9 @@ @Override public ImportStatistic apply(ProjectResource rsrc, Input input) - throws RestApiException, OrmException, IOException, ValidationException, - GitAPIException, NoSuchChangeException, NoSuchAccountException, - UpdateException, ConfigInvalidException, PermissionBackendException { + throws RestApiException, OrmException, IOException, ValidationException, GitAPIException, + NoSuchChangeException, NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { if (Strings.isNullOrEmpty(input.name)) { throw new BadRequestException("name is required"); } @@ -84,7 +81,8 @@ ImportProject.Input in = new ImportProject.Input(); in.name = rsrc.getName(); - return importProjectFactory.create(new Project.NameKey(input.name)) + return importProjectFactory + .create(new Project.NameKey(input.name)) .setCopy(true) .setErr(err) .apply(new ConfigResource(), in); @@ -99,9 +97,10 @@ } private boolean canCopy() { - return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) || - permissionBackend.user(currentUserProvider).testOrFalse( - new PluginPermission(pluginName, CopyProjectCapability.ID)); + return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) + || permissionBackend + .user(currentUserProvider) + .testOrFalse(new PluginPermission(pluginName, CopyProjectCapability.ID)); } void setErr(PrintWriter err) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCapability.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCapability.java index fe75fa6..a1b31a9 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCapability.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCapability.java
@@ -17,7 +17,7 @@ import com.google.gerrit.extensions.config.CapabilityDefinition; public class CopyProjectCapability extends CapabilityDefinition { - public final static String ID = "copyProject"; + public static final String ID = "copyProject"; @Override public String getDescription() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCommand.java index 8737d98..d94f4f1 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/CopyProjectCommand.java
@@ -21,7 +21,6 @@ import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; import com.google.inject.Inject; - import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -32,19 +31,15 @@ @Option(name = "--quiet", usage = "suppress progress messages") private boolean quiet; - @Argument(index = 0, required = true, metaVar = "NAME", - usage = "name of the source project") + @Argument(index = 0, required = true, metaVar = "NAME", usage = "name of the source project") private String source; - @Argument(index = 1, required = true, metaVar = "COPY", - usage = "name of the project copy") + @Argument(index = 1, required = true, metaVar = "COPY", usage = "name of the project copy") private String target; - @Inject - private ProjectsCollection projects; + @Inject private ProjectsCollection projects; - @Inject - private CopyProject copy; + @Inject private CopyProject copy; @Override protected void run() throws UnloggedFailure, Failure, Exception {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/GerritApi.java b/src/main/java/com/googlesource/gerrit/plugins/importer/GerritApi.java index 88cddce..ffa487c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/GerritApi.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/GerritApi.java
@@ -23,13 +23,11 @@ import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; - -import org.eclipse.jgit.errors.ConfigInvalidException; - import java.io.IOException; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.jgit.errors.ConfigInvalidException; interface GerritApi { @@ -49,31 +47,29 @@ } } - public ProjectInfo getProject(String projectName) throws BadRequestException, - IOException; + public ProjectInfo getProject(String projectName) throws BadRequestException, IOException; public List<ChangeInfo> queryChanges(String projectName, int start, int limit) throws BadRequestException, IOException; - public GroupInfo getGroup(String groupName) throws BadRequestException, - IOException, OrmException; + public GroupInfo getGroup(String groupName) throws BadRequestException, IOException, OrmException; /** * Retrieves inline comments of a patch set. * * @param changeId numeric change ID * @param rev the revision - * @return Iterable that provides the inline comments, or {@code null} if the - * revision does not exist + * @return Iterable that provides the inline comments, or {@code null} if the revision does not + * exist * @throws IOException thrown if sending the request fails - * @throws BadRequestException thrown if the response is neither - * {@code 200 OK} nor {@code 404 Not Found} + * @throws BadRequestException thrown if the response is neither {@code 200 OK} nor {@code 404 Not + * Found} */ public Iterable<CommentInfo> getComments(int changeId, String rev) throws BadRequestException, IOException, OrmException; - public List<SshKeyInfo> getSshKeys(String userId) throws BadRequestException, - IOException, OrmException, ConfigInvalidException; + public List<SshKeyInfo> getSshKeys(String userId) + throws BadRequestException, IOException, OrmException, ConfigInvalidException; public Version getVersion() throws BadRequestException, IOException; @@ -82,22 +78,25 @@ final Integer major; final Integer minor; final Integer patch; + final Integer revision; final String qualifier; Version(String formatted) { this.formatted = formatted; - Matcher m = Pattern.compile("(\\d+)\\.(\\d+)(\\.(\\d+))?(-(.+))?") - .matcher(formatted); + Matcher m = + Pattern.compile("(\\d+)\\.(\\d+)(\\.(\\d+))?(\\.(\\d+))?(-(.+))?").matcher(formatted); if (m.matches()) { this.major = Integer.parseInt(m.group(1)); this.minor = Integer.parseInt(m.group(2)); this.patch = m.group(3) != null ? Integer.parseInt(m.group(4)) : null; - this.qualifier = m.group(5) != null ? m.group(6) : null; + this.revision = m.group(5) != null ? Integer.parseInt(m.group(6)) : null; + this.qualifier = m.group(7) != null ? m.group(8) : null; } else { this.major = null; this.minor = null; this.patch = null; + this.revision = null; this.qualifier = null; } } @@ -108,7 +107,7 @@ // either of the compared version is not valid return -1; } - if (major == o.major) { + if (Objects.equal(major, o.major)) { if (Objects.equal(minor, o.minor)) { if (Objects.equal(patch, o.patch)) { return 0;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/GetImportedProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/GetImportedProject.java index ac72400..de6abd1 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/GetImportedProject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/GetImportedProject.java
@@ -17,7 +17,6 @@ import com.google.gerrit.extensions.annotations.RequiresCapability; import com.google.gerrit.extensions.restapi.RestReadView; import com.google.inject.Singleton; - import java.io.IOException; @Singleton
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/GitFetchStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/GitFetchStep.java index a3421d1..e51544b 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/GitFetchStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/GitFetchStep.java
@@ -17,7 +17,8 @@ import static com.googlesource.gerrit.plugins.importer.ProgressMonitorUtil.updateAndEnd; import com.google.inject.Singleton; - +import java.io.IOException; +import java.util.Map; import org.eclipse.jgit.api.FetchCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; @@ -30,20 +31,15 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; -import java.io.IOException; -import java.util.Map; - @Singleton class GitFetchStep { void fetch(String user, String password, Repository repo, ProgressMonitor pm) - throws InvalidRemoteException, TransportException, GitAPIException, - IOException { + throws InvalidRemoteException, TransportException, GitAPIException, IOException { pm.beginTask("Fetch project", 1); FetchCommand fetch = Git.wrap(repo).fetch(); if (user != null) { - fetch.setCredentialsProvider( - new UsernamePasswordCredentialsProvider(user, password)); + fetch.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); } fetch.setRemote("origin").call(); updateNonChangeRefs(repo); @@ -51,8 +47,7 @@ } private void updateNonChangeRefs(Repository repo) throws IOException { - Map<String, Ref> refs = repo.getRefDatabase().getRefs( - ConfigureRepositoryStep.R_IMPORTS); + Map<String, Ref> refs = repo.getRefDatabase().getRefs(ConfigureRepositoryStep.R_IMPORTS); for (Map.Entry<String, Ref> e : refs.entrySet()) { String name = e.getKey(); if (name.startsWith("imports/")) { @@ -86,8 +81,8 @@ case REJECTED_MISSING_OBJECT: case REJECTED_OTHER_REASON: default: - throw new IOException(String.format( - "Failed to update %s, RefUpdate.Result = %s", targetRef, result)); + throw new IOException( + String.format("Failed to update %s, RefUpdate.Result = %s", targetRef, result)); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java index 5b4c758..870ad9b 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/GroupCommand.java
@@ -26,48 +26,65 @@ import com.google.gerrit.sshd.SshCommand; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; - +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import org.eclipse.jgit.errors.ConfigInvalidException; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - @RequiresCapability(ImportCapability.ID) @CommandMetaData(name = "group", description = "Imports a group") public class GroupCommand extends SshCommand { - @Option(name = "--from", aliases = {"-f"}, required = true, metaVar = "URL", + @Option( + name = "--from", + aliases = {"-f"}, + required = true, + metaVar = "URL", usage = "URL of the remote system from where the group is imported from") private String url; - @Option(name = "--user", aliases = {"-u"}, required = true, metaVar = "NAME", + @Option( + name = "--user", + aliases = {"-u"}, + required = true, + metaVar = "NAME", usage = "user on remote system") private String user; - @Option(name = "--pass", aliases = {"-p"}, required = true, metaVar = "-|PASS", + @Option( + name = "--pass", + aliases = {"-p"}, + required = true, + metaVar = "-|PASS", usage = "password of remote user") private String pass; - @Option(name = "--import-owner-group", aliases = {"-o"}, + @Option( + name = "--import-owner-group", + aliases = {"-o"}, usage = "whether missing owner groups should be imported automatically") private boolean importOwnerGroup; - @Option(name = "--import-included-groups", aliases = {"-i"}, + @Option( + name = "--import-included-groups", + aliases = {"-i"}, usage = "whether missing included groups should be imported automatically") private boolean importIncludedGroups; - @Argument(index = 0, required = true, metaVar = "NAME", + @Argument( + index = 0, + required = true, + metaVar = "NAME", usage = "name of the group to be imported") private String group; - @Inject - private ImportGroup.Factory importGroupFactory; + @Inject private ImportGroup.Factory importGroupFactory; @Override - protected void run() throws UnloggedFailure, OrmException, IOException, - NoSuchAccountException, ConfigInvalidException { + protected void run() + throws UnloggedFailure, OrmException, IOException, NoSuchAccountException, + ConfigInvalidException { ImportGroup.Input input = new ImportGroup.Input(); input.from = url; input.user = user; @@ -76,9 +93,8 @@ input.importIncludedGroups = importIncludedGroups; try { - importGroupFactory.create(new AccountGroup.NameKey(group)).apply( - new ConfigResource(), input); - } catch (RestApiException e){ + importGroupFactory.create(new AccountGroup.NameKey(group)).apply(new ConfigResource(), input); + } catch (RestApiException e) { throw die(e.getMessage()); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/GroupsCollection.java b/src/main/java/com/googlesource/gerrit/plugins/importer/GroupsCollection.java index c25f5b5..3e7dfa9 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/GroupsCollection.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/GroupsCollection.java
@@ -28,17 +28,15 @@ import com.google.inject.Singleton; @Singleton -public class GroupsCollection implements - ChildCollection<ConfigResource, ImportGroupResource>, - AcceptsCreate<ConfigResource> { +public class GroupsCollection + implements ChildCollection<ConfigResource, ImportGroupResource>, AcceptsCreate<ConfigResource> { private final DynamicMap<RestView<ImportGroupResource>> views; private final ImportGroup.Factory importGroupFactory; @Inject GroupsCollection( - DynamicMap<RestView<ImportGroupResource>> views, - ImportGroup.Factory importGroupFactory) { + DynamicMap<RestView<ImportGroupResource>> views, ImportGroup.Factory importGroupFactory) { this.views = views; this.importGroupFactory = importGroupFactory; } @@ -60,8 +58,7 @@ } @Override - public ImportGroup create(ConfigResource parent, IdString id) - throws RestApiException { + public ImportGroup create(ConfigResource parent, IdString id) throws RestApiException { return importGroupFactory.create(new AccountGroup.NameKey(id.get())); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/importer/HttpModule.java index 7b6edf0..79fe837 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/HttpModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/HttpModule.java
@@ -32,7 +32,6 @@ DynamicSet.bind(binder(), WebUiPlugin.class) .toInstance(new JavaScriptPlugin("complete-project-import.js")); - DynamicSet.bind(binder(), WebUiPlugin.class) - .toInstance(new GwtPlugin("importer")); + DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new GwtPlugin("importer")); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/HttpResponse.java b/src/main/java/com/googlesource/gerrit/plugins/importer/HttpResponse.java index 4966c3c..7403c58 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/HttpResponse.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/HttpResponse.java
@@ -15,15 +15,13 @@ package com.googlesource.gerrit.plugins.importer; import com.google.common.base.Preconditions; - -import org.apache.http.client.methods.CloseableHttpResponse; -import org.eclipse.jgit.util.IO; -import org.eclipse.jgit.util.RawParseUtils; - import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.nio.ByteBuffer; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.eclipse.jgit.util.IO; +import org.eclipse.jgit.util.RawParseUtils; public class HttpResponse implements AutoCloseable { @@ -61,15 +59,8 @@ public String getEntityContent() throws IOException { Preconditions.checkNotNull(response, "Response is not initialized."); - Preconditions.checkNotNull(response.getEntity(), - "Response.Entity is not initialized."); - ByteBuffer buf = IO.readWholeStream( - response.getEntity().getContent(), - 1024); - return RawParseUtils.decode( - buf.array(), - buf.arrayOffset(), - buf.limit()) - .trim(); + Preconditions.checkNotNull(response.getEntity(), "Response.Entity is not initialized."); + ByteBuffer buf = IO.readWholeStream(response.getEntity().getContent(), 1024); + return RawParseUtils.decode(buf.array(), buf.arrayOffset(), buf.limit()).trim(); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/HttpSession.java b/src/main/java/com/googlesource/gerrit/plugins/importer/HttpSession.java index af7af86..88fa9cd 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/HttpSession.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/HttpSession.java
@@ -15,7 +15,16 @@ package com.googlesource.gerrit.plugins.importer; import com.google.common.base.CharMatcher; - +import java.io.IOException; +import java.net.URI; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.methods.HttpGet; @@ -24,18 +33,6 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import java.io.IOException; -import java.net.URI; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.X509Certificate; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - public class HttpSession { protected final String url; @@ -58,13 +55,12 @@ if (client == null) { URI uri = URI.create(url); BasicCredentialsProvider creds = new BasicCredentialsProvider(); - creds.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), - new UsernamePasswordCredentials(user, pass)); + creds.setCredentials( + new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(user, pass)); SSLContext context; try { - final TrustManager[] trustAllCerts = - new TrustManager[] {new DummyX509TrustManager()}; + final TrustManager[] trustAllCerts = new TrustManager[] {new DummyX509TrustManager()}; context = SSLContext.getInstance("TLS"); context.init(null, trustAllCerts, null); } catch (KeyManagementException | NoSuchAlgorithmException e) { @@ -73,14 +69,13 @@ SSLConnectionSocketFactory sf; sf = new SSLConnectionSocketFactory(context, new DummyHostnameVerifier()); - client = HttpClients - .custom() - .setSSLSocketFactory(sf) - .setDefaultCredentialsProvider(creds) - .setMaxConnPerRoute(10) - .setMaxConnTotal(1024) - .build(); - + client = + HttpClients.custom() + .setSSLSocketFactory(sf) + .setDefaultCredentialsProvider(creds) + .setMaxConnPerRoute(10) + .setMaxConnTotal(1024) + .build(); } return client; } @@ -109,5 +104,4 @@ return true; } } - }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportCapability.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportCapability.java index bb18ef3..d2bd3e5 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportCapability.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportCapability.java
@@ -17,7 +17,7 @@ import com.google.gerrit.extensions.config.CapabilityDefinition; public class ImportCapability extends CapabilityDefinition { - public final static String ID = "import"; + public static final String ID = "import"; @Override public String getDescription() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java index 6c64783..c41fdbf 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroup.java
@@ -48,14 +48,7 @@ import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; - import com.googlesource.gerrit.plugins.importer.ImportGroup.Input; - -import org.eclipse.jgit.errors.ConfigInvalidException; -import org.eclipse.jgit.lib.Config; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -63,6 +56,10 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.lib.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @RequiresCapability(ImportCapability.ID) class ImportGroup implements RestModifyView<ConfigResource, Input> { @@ -118,8 +115,8 @@ @Override public Response<String> apply(ConfigResource rsrc, Input input) - throws NoSuchAccountException, OrmException, IOException, - RestApiException, ConfigInvalidException { + throws NoSuchAccountException, OrmException, IOException, RestApiException, + ConfigInvalidException { GroupInfo groupInfo; this.api = apiFactory.create(input.from, input.user, input.pass); groupInfo = api.getGroup(group.get()); @@ -130,22 +127,24 @@ } private void validate(Input input, GroupInfo groupInfo) - throws IOException, OrmException, NoSuchAccountException, - RestApiException, ConfigInvalidException { + throws IOException, OrmException, NoSuchAccountException, RestApiException, + ConfigInvalidException { if (!isInternalGroup(new AccountGroup.UUID(groupInfo.id))) { - throw new MethodNotAllowedException(String.format( - "Group with name %s is not an internal group and cannot be imported", - groupInfo.name)); + throw new MethodNotAllowedException( + String.format( + "Group with name %s is not an internal group and cannot be imported", + groupInfo.name)); } if (getGroupByUUID(groupInfo.id) != null) { - throw new ResourceConflictException(String.format( - "Group with UUID %s already exists", groupInfo.id)); + throw new ResourceConflictException( + String.format("Group with UUID %s already exists", groupInfo.id)); } if (!groupInfo.id.equals(groupInfo.ownerId)) if (!input.importOwnerGroup && getGroupByUUID(groupInfo.ownerId) == null) { - throw new PreconditionFailedException(String.format( - "Owner group %s with UUID %s does not exist", - getGroupName(groupInfo.ownerId), groupInfo.ownerId)); + throw new PreconditionFailedException( + String.format( + "Owner group %s with UUID %s does not exist", + getGroupName(groupInfo.ownerId), groupInfo.ownerId)); } if (groupInfo.members != null) { for (AccountInfo member : groupInfo.members) { @@ -160,9 +159,10 @@ if (groupInfo.includes != null) { for (GroupInfo include : groupInfo.includes) { if (getGroupByUUID(include.id) == null) { - throw new PreconditionFailedException(String.format( - "Included group %s with UUID %s does not exist", - getGroupName(include.id), include.id)); + throw new PreconditionFailedException( + String.format( + "Included group %s with UUID %s does not exist", + getGroupName(include.id), include.id)); } } } @@ -186,8 +186,8 @@ } private CreateGroupArgs toCreateGroupArgs(GroupInfo groupInfo) - throws IOException, OrmException, NoSuchAccountException, - RestApiException, ConfigInvalidException { + throws IOException, OrmException, NoSuchAccountException, RestApiException, + ConfigInvalidException { CreateGroupArgs args = new CreateGroupArgs(); args.setGroupName(groupInfo.name); args.groupDescription = groupInfo.description; @@ -204,12 +204,13 @@ } private AccountGroup createGroup(Input input, GroupInfo info) - throws OrmException, NoSuchAccountException, IOException, - RestApiException, ConfigInvalidException { + throws OrmException, NoSuchAccountException, IOException, RestApiException, + ConfigInvalidException { String uniqueName = getUniqueGroupName(info.name); if (!info.name.equals(uniqueName)) { - log.warn(String.format("Group %s with UUID %s is imported with name %s", - info.name, info.id, uniqueName)); + log.warn( + String.format( + "Group %s with UUID %s is imported with name %s", info.name, info.id, uniqueName)); info.name = uniqueName; } AccountGroup group = createAccountGroup(info); @@ -230,12 +231,14 @@ if (isInternalGroup(new AccountGroup.UUID(info.ownerId))) { String ownerGroupName = getGroupName(info.ownerId); if (input.importOwnerGroup) { - importGroupFactory.create(new AccountGroup.NameKey(ownerGroupName)) + importGroupFactory + .create(new AccountGroup.NameKey(ownerGroupName)) .apply(new ConfigResource(), input); } else { - throw new IllegalStateException(String.format( - "Cannot set non-existing group %s as owner of group %s.", - ownerGroupName, info.name)); + throw new IllegalStateException( + String.format( + "Cannot set non-existing group %s as owner of group %s.", + ownerGroupName, info.name)); } } } @@ -269,23 +272,21 @@ } } return getUniqueGroupName(String.format("%s_imported", name), true); - } + private AccountGroup createAccountGroup(GroupInfo info) throws OrmException { AccountGroup.Id groupId = new AccountGroup.Id(db.nextAccountGroupId()); AccountGroup.UUID uuid = new AccountGroup.UUID(info.id); AccountGroup group = - new AccountGroup(new AccountGroup.NameKey(info.name), groupId, uuid, - TimeUtil.nowTs()); - group.setVisibleToAll(cfg.getBoolean("groups", "newGroupsVisibleToAll", - false)); + new AccountGroup(new AccountGroup.NameKey(info.name), groupId, uuid, TimeUtil.nowTs()); + group.setVisibleToAll(cfg.getBoolean("groups", "newGroupsVisibleToAll", false)); group.setDescription(info.description); return group; } private void addMembers(AccountGroup.Id groupId, List<AccountInfo> members) - throws OrmException, NoSuchAccountException, IOException, - RestApiException, ConfigInvalidException { + throws OrmException, NoSuchAccountException, IOException, RestApiException, + ConfigInvalidException { List<AccountGroupMember> memberships = new ArrayList<>(); for (AccountInfo member : members) { Account.Id userId = accountUtil.resolveUser(api, member); @@ -300,23 +301,24 @@ } } - private void addGroups(Input input, AccountGroup.Id groupId, String groupName, - List<GroupInfo> includedGroups) - throws NoSuchAccountException, OrmException, IOException, - RestApiException, ConfigInvalidException { + private void addGroups( + Input input, AccountGroup.Id groupId, String groupName, List<GroupInfo> includedGroups) + throws NoSuchAccountException, OrmException, IOException, RestApiException, + ConfigInvalidException { List<AccountGroupById> includeList = new ArrayList<>(); for (GroupInfo includedGroup : includedGroups) { if (isInternalGroup(new AccountGroup.UUID(includedGroup.id))) { if (getGroupByUUID(includedGroup.id) == null) { String includedGroupName = getGroupName(includedGroup.id); if (input.importIncludedGroups) { - importGroupFactory.create( - new AccountGroup.NameKey(includedGroupName)).apply( - new ConfigResource(), input); + importGroupFactory + .create(new AccountGroup.NameKey(includedGroupName)) + .apply(new ConfigResource(), input); } else { - throw new IllegalStateException(String.format( - "Cannot include non-existing group %s into group %s.", - includedGroupName, groupName)); + throw new IllegalStateException( + String.format( + "Cannot include non-existing group %s into group %s.", + includedGroupName, groupName)); } } } @@ -332,8 +334,7 @@ } } - private String getGroupName(String uuid) throws BadRequestException, - IOException, OrmException { + private String getGroupName(String uuid) throws BadRequestException, IOException, OrmException { return api.getGroup(uuid).name; } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java index e8b0288..308ba83 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportGroupsStep.java
@@ -29,12 +29,10 @@ import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; - -import org.eclipse.jgit.errors.ConfigInvalidException; -import org.eclipse.jgit.lib.ProgressMonitor; - import java.io.IOException; import java.util.Set; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.lib.ProgressMonitor; public class ImportGroupsStep { @@ -76,8 +74,9 @@ this.pm = pm; } - void importGroups() throws NoSuchAccountException, OrmException, IOException, - RestApiException, ConfigInvalidException { + void importGroups() + throws NoSuchAccountException, OrmException, IOException, RestApiException, + ConfigInvalidException { ProjectConfig projectConfig = projectCache.get(project).getConfig(); Set<AccountGroup.UUID> groupUUIDs = projectConfig.getAllGroupUUIDs(); pm.beginTask("Import Groups", groupUUIDs.size()); @@ -91,9 +90,9 @@ input.importOwnerGroup = true; input.importIncludedGroups = true; try { - importGroupFactory.create( - new AccountGroup.NameKey(projectConfig.getGroup(groupUUID) - .getName())).apply(new ConfigResource(), input); + importGroupFactory + .create(new AccountGroup.NameKey(projectConfig.getGroup(groupUUID).getName())) + .apply(new ConfigResource(), input); } catch (ResourceConflictException | MethodNotAllowedException e) { // should not happen throw new IllegalStateException(e);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportInfo.java index 16be1c6..97c50f6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportInfo.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportInfo.java
@@ -15,7 +15,6 @@ package com.googlesource.gerrit.plugins.importer; import com.google.gerrit.extensions.common.AccountInfo; - import java.sql.Timestamp; public class ImportInfo {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportJson.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportJson.java index f5cd59a..d8db8e9 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportJson.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportJson.java
@@ -27,18 +27,15 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; - import com.googlesource.gerrit.plugins.importer.ImportProject.Input; - -import org.eclipse.jgit.internal.storage.file.LockFile; -import org.eclipse.jgit.lib.ProgressMonitor; - import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.OutputStream; import java.sql.Timestamp; import java.util.ArrayList; +import org.eclipse.jgit.internal.storage.file.LockFile; +import org.eclipse.jgit.lib.ProgressMonitor; @Singleton public class ImportJson { @@ -47,15 +44,12 @@ private final AccountLoader.Factory accountLoaderFactory; @Inject - ImportJson( - Provider<CurrentUser> currentUser, - AccountLoader.Factory accountLoaderFactory) { + ImportJson(Provider<CurrentUser> currentUser, AccountLoader.Factory accountLoaderFactory) { this.currentUser = currentUser; this.accountLoaderFactory = accountLoaderFactory; } - public ImportProjectInfo format(Input input, ImportProjectInfo info) - throws OrmException { + public ImportProjectInfo format(Input input, ImportProjectInfo info) throws OrmException { if (info == null) { info = new ImportProjectInfo(); info.from = input.from; @@ -72,15 +66,14 @@ AccountLoader accountLoader = accountLoaderFactory.create(true); ImportInfo importInfo = new ImportInfo(); importInfo.timestamp = new Timestamp(TimeUtil.nowMs()); - importInfo.user = - accountLoader.get(((IdentifiedUser) currentUser.get()).getAccountId()); + importInfo.user = accountLoader.get(((IdentifiedUser) currentUser.get()).getAccountId()); importInfo.remoteUser = remoteUser; accountLoader.fill(); return importInfo; } - public static void persist(LockFile lockFile, ImportProjectInfo info, - ProgressMonitor pm) throws IOException { + public static void persist(LockFile lockFile, ImportProjectInfo info, ProgressMonitor pm) + throws IOException { pm.beginTask("Persist parameters", 1); String s = OutputFormat.JSON_COMPACT.newGson().toJson(info); try (OutputStream out = lockFile.getOutputStream()) { @@ -94,8 +87,9 @@ public static ImportProjectInfo parse(File f) throws IOException { try (FileReader r = new FileReader(f)) { - return OutputFormat.JSON_COMPACT.newGson().fromJson(r, - new TypeToken<ImportProjectInfo>() {}.getType()); + return OutputFormat.JSON_COMPACT + .newGson() + .fromJson(r, new TypeToken<ImportProjectInfo>() {}.getType()); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLog.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLog.java index 597c4fc..c61e50d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLog.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLog.java
@@ -28,7 +28,6 @@ import com.google.gerrit.server.util.SystemLog; import com.google.inject.Inject; import com.google.inject.Singleton; - import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; @@ -50,7 +49,8 @@ private final String canonicalWebUrl; @Inject - public ImportLog(SystemLog systemLog, + public ImportLog( + SystemLog systemLog, ServerInformation serverInfo, AuditService auditService, @CanonicalWebUrl String canonicalWebUrl) { @@ -59,30 +59,35 @@ this.canonicalWebUrl = canonicalWebUrl; } - public void onImport(IdentifiedUser user, Project.NameKey srcProject, - Project.NameKey targetProject, String from) { + public void onImport( + IdentifiedUser user, Project.NameKey srcProject, Project.NameKey targetProject, String from) { onImport(user, srcProject, targetProject, from, null); } - public void onImport(IdentifiedUser user, Project.NameKey srcProject, - Project.NameKey targetProject, String from, Exception ex) { + public void onImport( + IdentifiedUser user, + Project.NameKey srcProject, + Project.NameKey targetProject, + String from, + Exception ex) { long ts = TimeUtil.nowMs(); - LoggingEvent event = new LoggingEvent( // - Logger.class.getName(), // fqnOfCategoryClass - log, // logger - ts, // when - ex == null // level - ? Level.INFO - : Level.ERROR, - ex == null // message text - ? "OK" - : "FAIL", - Thread.currentThread().getName(), // thread name - null, // exception information - null, // current NDC string - null, // caller location - null // MDC properties - ); + LoggingEvent event = + new LoggingEvent( // + Logger.class.getName(), // fqnOfCategoryClass + log, // logger + ts, // when + ex == null // level + ? Level.INFO + : Level.ERROR, + ex == null // message text + ? "OK" + : "FAIL", + Thread.currentThread().getName(), // thread name + null, // exception information + null, // current NDC string + null, // caller location + null // MDC properties + ); event.setProperty(ACCOUNT_ID, user.getAccountId().toString()); event.setProperty(USER_NAME, user.getUserName()); @@ -105,10 +110,9 @@ audit(user, ts, srcProject, from, ex); } - private void audit(IdentifiedUser user, long ts, Project.NameKey project, - String from, Exception ex) { - ListMultimap<String, Object> params = - MultimapBuilder.hashKeys().arrayListValues().build(); + private void audit( + IdentifiedUser user, long ts, Project.NameKey project, String from, Exception ex) { + ListMultimap<String, Object> params = MultimapBuilder.hashKeys().arrayListValues().build(); params.put("class", ImportLog.class); params.put("project", project.get()); params.put("from", from); @@ -124,7 +128,6 @@ params, // params ex != null // result ? ex.toString() - : "OK" - )); + : "OK")); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLogLayout.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLogLayout.java index cc29340..7faceae 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLogLayout.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportLogLayout.java
@@ -14,14 +14,13 @@ package com.googlesource.gerrit.plugins.importer; -import org.apache.log4j.Layout; -import org.apache.log4j.spi.LoggingEvent; -import org.eclipse.jgit.util.QuotedString; - import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; +import org.apache.log4j.Layout; +import org.apache.log4j.spi.LoggingEvent; +import org.eclipse.jgit.util.QuotedString; final class ImportLogLayout extends Layout { private final Calendar calendar; @@ -29,7 +28,7 @@ private final char[] lastTimeString = new char[20]; private final char[] timeZone; - public ImportLogLayout() { + public ImportLogLayout() { TimeZone tz = TimeZone.getDefault(); calendar = Calendar.getInstance(tz); @@ -41,14 +40,12 @@ /** * Formats the events in the import log. * - * A successful project import will result in a log entry like this: - * [2015-03-05 09:13:28,912 +0100] INFO 1000000 admin OK \ - * https://some-gerrit-server:8080 srcName targetName + * <p>A successful project import will result in a log entry like this: [2015-03-05 09:13:28,912 + * +0100] INFO 1000000 admin OK \ https://some-gerrit-server:8080 srcName targetName * - * The log entry for a failed project import will look like this: - * [2015-03-05 12:14:30,180 +0100] ERROR 1000000 admin FAIL \ - * https://some-gerrit-server:8080 srcName targetName \ - * com.google.gwtorm.server.OrmException: Failed to access the database + * <p>The log entry for a failed project import will look like this: [2015-03-05 12:14:30,180 + * +0100] ERROR 1000000 admin FAIL \ https://some-gerrit-server:8080 srcName targetName \ + * com.google.gwtorm.server.OrmException: Failed to access the database */ @Override public String format(LoggingEvent event) { @@ -139,6 +136,5 @@ } @Override - public void activateOptions() { - } + public void activateOptions() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportMenu.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportMenu.java index 2edfdc1..6e606d8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportMenu.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportMenu.java
@@ -25,7 +25,6 @@ import com.google.gerrit.server.permissions.PermissionBackend; import com.google.inject.Inject; import com.google.inject.Provider; - import java.util.List; public class ImportMenu implements TopMenu { @@ -60,9 +59,10 @@ } private boolean canImport() { - return permissionBackend.user(userProvider).testOrFalse( - new PluginPermission(pluginName, ImportCapability.ID)) || - permissionBackend.user(userProvider).testOrFalse(ADMINISTRATE_SERVER); + return permissionBackend + .user(userProvider) + .testOrFalse(new PluginPermission(pluginName, ImportCapability.ID)) + || permissionBackend.user(userProvider).testOrFalse(ADMINISTRATE_SERVER); } @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java index 9e7c61b..b399ed1 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProject.java
@@ -28,20 +28,22 @@ import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.config.ConfigResource; -import com.google.gerrit.server.update.UpdateException; +import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectState; +import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.validators.ValidationException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.assistedinject.Assisted; - import com.googlesource.gerrit.plugins.importer.GerritApi.Version; import com.googlesource.gerrit.plugins.importer.ImportProject.Input; - +import java.io.File; +import java.io.IOException; +import java.io.Writer; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.internal.storage.file.LockFile; @@ -52,10 +54,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.Writer; - @RequiresCapability(ImportCapability.ID) class ImportProject implements RestModifyView<ConfigResource, Input> { public static class Input { @@ -165,9 +163,9 @@ @Override public ImportStatistic apply(ConfigResource rsrc, Input input) - throws RestApiException, OrmException, IOException, ValidationException, - GitAPIException, NoSuchChangeException, NoSuchAccountException, - UpdateException, ConfigInvalidException, PermissionBackendException { + throws RestApiException, OrmException, IOException, ValidationException, GitAPIException, + NoSuchChangeException, NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { if (input == null) { input = new Input(); } @@ -180,10 +178,10 @@ } } - public ResumeImportStatistic resume(String user, String pass, boolean force, - File importStatus) throws RestApiException, OrmException, IOException, - GitAPIException, NoSuchChangeException, NoSuchAccountException, - UpdateException, ConfigInvalidException, PermissionBackendException { + public ResumeImportStatistic resume(String user, String pass, boolean force, File importStatus) + throws RestApiException, OrmException, IOException, GitAPIException, NoSuchChangeException, + NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { LockFile lockFile = lockForImport(); try { ImportProjectInfo info = ImportJson.parse(importStatus); @@ -203,11 +201,10 @@ } } - private ResumeImportStatistic apply(LockFile lockFile, Input input, - ImportProjectInfo info) throws RestApiException, OrmException, - IOException, GitAPIException, NoSuchChangeException, - NoSuchAccountException, UpdateException, ConfigInvalidException, - PermissionBackendException { + private ResumeImportStatistic apply(LockFile lockFile, Input input, ImportProjectInfo info) + throws RestApiException, OrmException, IOException, GitAPIException, NoSuchChangeException, + NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { boolean resume = info != null; api = apiFactory.create(input.from, input.user, input.pass); @@ -217,49 +214,49 @@ input.validateImport(); Version v = api.getVersion(); if (v.compareTo(v2_11_2) < 0) { - throw new BadRequestException(String.format( - "The version of the source Gerrit server %s is too old. " - + "Its version is %s, but required is a version >= %s.", - input.from, v.formatted, v2_11_2)); + throw new BadRequestException( + String.format( + "The version of the source Gerrit server %s is too old. " + + "Its version is %s, but required is a version >= %s.", + input.from, v.formatted, v2_11_2)); } } - ProgressMonitor pm = err != null ? new TextProgressMonitor(err) : - NullProgressMonitor.INSTANCE; + ProgressMonitor pm = err != null ? new TextProgressMonitor(err) : NullProgressMonitor.INSTANCE; ResumeImportStatistic statistic = new ResumeImportStatistic(); try { - srcProject = !Strings.isNullOrEmpty(input.name) - ? new Project.NameKey(input.name) : targetProject; + srcProject = + !Strings.isNullOrEmpty(input.name) ? new Project.NameKey(input.name) : targetProject; checkProjectInSource(pm); setParentProjectName(input, pm); checkPreconditions(pm); - try (Repository repo = openRepoStep.open(targetProject, resume, pm, - parent)) { + try (Repository repo = openRepoStep.open(targetProject, resume, pm, parent)) { ImportJson.persist(lockFile, importJson.format(input, info), pm); configRepoStep.configure(repo, srcProject, input.from, pm); gitFetchStep.fetch(input.user, input.pass, repo, pm); configProjectStep.configure(targetProject, parent, pm); - replayChangesFactory.create(input.from, api, repo, - srcProject, targetProject, force, resume, statistic, pm).replay(); + replayChangesFactory + .create(input.from, api, repo, srcProject, targetProject, force, resume, statistic, pm) + .replay(); if (!copy) { - importGroupsStepFactory.create(input.from, input.user, input.pass, - targetProject, pm).importGroups(); + importGroupsStepFactory + .create(input.from, input.user, input.pass, targetProject, pm) + .importGroups(); } } - importLog.onImport((IdentifiedUser) currentUser.get(), srcProject, - targetProject, input.from); + importLog.onImport((IdentifiedUser) currentUser.get(), srcProject, targetProject, input.from); } catch (BadRequestException e) { throw e; } catch (Exception e) { - importLog.onImport((IdentifiedUser) currentUser.get(), srcProject, - targetProject, input.from, e); - String msg = input.from != null - ? format("Unable to transfer project '%s' from" - + " source gerrit host '%s'.", - srcProject.get(), input.from) - : format("Unable to copy project '%s'.", - srcProject.get()); + importLog.onImport( + (IdentifiedUser) currentUser.get(), srcProject, targetProject, input.from, e); + String msg = + input.from != null + ? format( + "Unable to transfer project '%s' from" + " source gerrit host '%s'.", + srcProject.get(), input.from) + : format("Unable to copy project '%s'.", srcProject.get()); log.error(msg, e); throw e; } @@ -267,8 +264,7 @@ return statistic; } - private void checkProjectInSource(ProgressMonitor pm) - throws IOException, BadRequestException { + private void checkProjectInSource(ProgressMonitor pm) throws IOException, BadRequestException { pm.beginTask("Check source project", 1); api.getProject(srcProject.get()); updateAndEnd(pm); @@ -281,8 +277,7 @@ if (!Strings.isNullOrEmpty(input.parent)) { parent = new Project.NameKey(input.parent); } else { - parent = new Project.NameKey( - api.getProject(srcProject.get()).parent); + parent = new Project.NameKey(api.getProject(srcProject.get()).parent); } } updateAndEnd(pm); @@ -297,8 +292,8 @@ } ProjectState p = projectCache.get(parent); if (p == null) { - throw new BadRequestException(format( - "Parent project '%s' does not exist in target.", parent.get())); + throw new BadRequestException( + format("Parent project '%s' does not exist in target.", parent.get())); } updateAndEnd(pm); } @@ -310,8 +305,7 @@ if (lockFile.lock()) { return lockFile; } - throw new ResourceConflictException( - "project is being imported from another session"); + throw new ResourceConflictException("project is being imported from another session"); } catch (IOException e1) { throw new ResourceConflictException("failed to lock project for import"); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectResource.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectResource.java index 93b6a68..987b448 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectResource.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectResource.java
@@ -18,7 +18,6 @@ import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.reviewdb.client.Project; import com.google.inject.TypeLiteral; - import java.io.File; import java.io.IOException;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/InsertLinkToOriginalChangeStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/InsertLinkToOriginalChangeStep.java index eb3dbe9..337b36c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/InsertLinkToOriginalChangeStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/InsertLinkToOriginalChangeStep.java
@@ -33,7 +33,6 @@ import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; - import java.io.IOException; class InsertLinkToOriginalChangeStep { @@ -52,14 +51,12 @@ interface Factory { InsertLinkToOriginalChangeStep create( - @Nullable String fromGerrit, - Change change, - ChangeInfo changeInfo, - boolean resume); + @Nullable String fromGerrit, Change change, ChangeInfo changeInfo, boolean resume); } @Inject - InsertLinkToOriginalChangeStep(CurrentUser currentUser, + InsertLinkToOriginalChangeStep( + CurrentUser currentUser, ChangeUpdate.Factory updateFactory, IdentifiedUser.GenericFactory genericUserFactory, ChangeData.Factory changeDataFactory, @@ -84,14 +81,13 @@ } void insert() throws NoSuchChangeException, OrmException, IOException { - insertMessage(change, (resume ? "Resumed import of " : "Imported from ") - + changeUrl(changeInfo)); + insertMessage( + change, (resume ? "Resumed import of " : "Imported from ") + changeUrl(changeInfo)); } private String changeUrl(ChangeInfo c) { StringBuilder url = new StringBuilder(); - url.append(ensureSlash( - MoreObjects.firstNonNull(fromGerrit, canonicalWebUrl))); + url.append(ensureSlash(MoreObjects.firstNonNull(fromGerrit, canonicalWebUrl))); url.append(c._number); return url.toString(); } @@ -102,8 +98,10 @@ ChangeData cd = changeDataFactory.create(db, change); ChangeUpdate update = updateFactory.create(cd.notes(), genericUserFactory.create(userId)); ChangeMessage cmsg = - new ChangeMessage(new ChangeMessage.Key(change.getId(), - ChangeUtil.messageUuid()), userId, TimeUtil.nowTs(), + new ChangeMessage( + new ChangeMessage.Key(change.getId(), ChangeUtil.messageUuid()), + userId, + TimeUtil.nowTs(), change.currentPatchSetId()); cmsg.setMessage(message); cmUtil.addChangeMessage(db, update, cmsg);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportedProjects.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportedProjects.java index c63db70..2e6379c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportedProjects.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportedProjects.java
@@ -21,9 +21,6 @@ import com.google.gerrit.server.config.ConfigResource; import com.google.inject.Inject; import com.google.inject.Singleton; - -import org.kohsuke.args4j.Option; - import java.io.File; import java.io.IOException; import java.nio.file.Path; @@ -31,6 +28,7 @@ import java.util.HashSet; import java.util.Locale; import java.util.Map; +import org.kohsuke.args4j.Option; @Singleton @RequiresCapability(ImportCapability.ID) @@ -38,7 +36,9 @@ private final ProjectsCollection projects; - @Option(name = "--match", metaVar = "MATCH", + @Option( + name = "--match", + metaVar = "MATCH", usage = "List only projects containing this substring, case insensitive") public void setMatch(String match) { this.match = match.toLowerCase(Locale.ENGLISH); @@ -52,8 +52,7 @@ } @Override - public Map<String, ImportProjectInfo> apply(ConfigResource rsrc) - throws IOException { + public Map<String, ImportProjectInfo> apply(ConfigResource rsrc) throws IOException { Map<String, ImportProjectInfo> importedProjects = Maps.newTreeMap(); for (File f : listImportFiles()) { importedProjects.put(projects.FS_LAYOUT.resolveProjectName(f), ImportJson.parse(f)); @@ -76,7 +75,6 @@ } private boolean matches(Path p) { - return match == null - || p.toString().toLowerCase(Locale.ENGLISH).contains(match); + return match == null || p.toString().toLowerCase(Locale.ENGLISH).contains(match); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportsCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportsCommand.java index 701453a..d242cf4 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportsCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ListImportsCommand.java
@@ -21,27 +21,30 @@ import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; import com.google.inject.Inject; - -import org.kohsuke.args4j.Argument; -import org.kohsuke.args4j.Option; - import java.io.IOException; import java.util.Map; +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.Option; @RequiresCapability(ImportCapability.ID) @CommandMetaData(name = "list-projects", description = "Lists project imports") class ListProjectImportsCommand extends SshCommand { - @Option(name = "--verbose", aliases = {"-v"}, required = false, + @Option( + name = "--verbose", + aliases = {"-v"}, + required = false, usage = "Print detailed info for each project import") private boolean verbose; - @Argument(index = 0, required = false, metaVar = "MATCH", + @Argument( + index = 0, + required = false, + metaVar = "MATCH", usage = "List only projects containing this substring, case insensitive") private String match; - @Inject - private ListImportedProjects list; + @Inject private ListImportedProjects list; @Override protected void run() throws IOException { @@ -58,8 +61,7 @@ stdout.println(" parent: " + info.parent); stdout.println(format(" %-23s %s:%s", "time", "user", "remote-user")); for (ImportInfo i : info.imports) { - stdout.println( - format(" %-23s %s:%s", i.timestamp, i.user.username, i.remoteUser)); + stdout.println(format(" %-23s %s:%s", i.timestamp, i.user.username, i.remoteUser)); } stdout.println(); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/LocalApi.java b/src/main/java/com/googlesource/gerrit/plugins/importer/LocalApi.java index 9248b8c..e3030aa 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/LocalApi.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/LocalApi.java
@@ -34,12 +34,10 @@ import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; - -import org.eclipse.jgit.errors.ConfigInvalidException; - import java.io.IOException; import java.util.List; import java.util.Map; +import org.eclipse.jgit.errors.ConfigInvalidException; public class LocalApi implements GerritApi { private final com.google.gerrit.extensions.api.GerritApi gApi; @@ -57,8 +55,7 @@ } @Override - public ProjectInfo getProject(String projectName) throws IOException, - BadRequestException { + public ProjectInfo getProject(String projectName) throws IOException, BadRequestException { try { return gApi.projects().name(projectName).get(); } catch (RestApiException e) { @@ -67,13 +64,11 @@ } @Override - public List<ChangeInfo> queryChanges(String projectName, int start, - int limit) throws IOException, - BadRequestException { + public List<ChangeInfo> queryChanges(String projectName, int start, int limit) + throws IOException, BadRequestException { try { - QueryRequest query = gApi.changes() - .query("project:" + projectName); + QueryRequest query = gApi.changes().query("project:" + projectName); query .withStart(start) .withOptions( @@ -83,7 +78,7 @@ ListChangesOption.CURRENT_REVISION, ListChangesOption.ALL_REVISIONS, ListChangesOption.ALL_COMMITS); - if(limit > 0) { + if (limit > 0) { query.withLimit(limit); } return query.get(); @@ -93,8 +88,8 @@ } @Override - public GroupInfo getGroup(String groupName) throws IOException, - BadRequestException, OrmException { + public GroupInfo getGroup(String groupName) + throws IOException, BadRequestException, OrmException { try { return gApi.groups().id(groupName).get(); } catch (RestApiException e) { @@ -106,8 +101,7 @@ public Iterable<CommentInfo> getComments(int changeId, String rev) throws IOException, OrmException, BadRequestException { try { - Map<String, List<CommentInfo>> result = - gApi.changes().id(changeId).revision(rev).comments(); + Map<String, List<CommentInfo>> result = gApi.changes().id(changeId).revision(rev).comments(); for (Map.Entry<String, List<CommentInfo>> e : result.entrySet()) { for (CommentInfo i : e.getValue()) { @@ -122,12 +116,11 @@ } @Override - public List<SshKeyInfo> getSshKeys(String userId) throws BadRequestException, - IOException, OrmException, ConfigInvalidException { + public List<SshKeyInfo> getSshKeys(String userId) + throws BadRequestException, IOException, OrmException, ConfigInvalidException { try { AccountResource rsrc = - accounts.parse(TopLevelResource.INSTANCE, - IdString.fromDecoded(userId)); + accounts.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(userId)); return getSshKeys.apply(rsrc); } catch (ResourceNotFoundException | AuthException | PermissionBackendException e) { throw new BadRequestException(e.getMessage());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java b/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java index 7c2c2d4..e8f7189 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/Module.java
@@ -38,28 +38,27 @@ bind(CapabilityDefinition.class) .annotatedWith(Exports.named(CopyProjectCapability.ID)) .to(CopyProjectCapability.class); - install(new RestApiModule() { - @Override - protected void configure() { - DynamicMap.mapOf(binder(), IMPORT_PROJECT_KIND); - DynamicMap.mapOf(binder(), IMPORT_GROUP_KIND); + install( + new RestApiModule() { + @Override + protected void configure() { + DynamicMap.mapOf(binder(), IMPORT_PROJECT_KIND); + DynamicMap.mapOf(binder(), IMPORT_GROUP_KIND); - child(CONFIG_KIND, "projects").to(ProjectsCollection.class); - get(IMPORT_PROJECT_KIND).to(GetImportedProject.class); - put(IMPORT_PROJECT_KIND, "resume").to(ResumeProjectImport.class); - delete(IMPORT_PROJECT_KIND).to(CompleteProjectImport.class); + child(CONFIG_KIND, "projects").to(ProjectsCollection.class); + get(IMPORT_PROJECT_KIND).to(GetImportedProject.class); + put(IMPORT_PROJECT_KIND, "resume").to(ResumeProjectImport.class); + delete(IMPORT_PROJECT_KIND).to(CompleteProjectImport.class); - put(PROJECT_KIND, "copy").to(CopyProject.class); - put(PROJECT_KIND, "copy.resume").to(ResumeCopyProject.class); - put(PROJECT_KIND, "import.resume").to(ResumeProjectImport.OnProjects.class); - post(PROJECT_KIND, "delete").to(CompleteProjectImport.OnProjects.class); + put(PROJECT_KIND, "copy").to(CopyProject.class); + put(PROJECT_KIND, "copy.resume").to(ResumeCopyProject.class); + put(PROJECT_KIND, "import.resume").to(ResumeProjectImport.OnProjects.class); + post(PROJECT_KIND, "delete").to(CompleteProjectImport.OnProjects.class); - child(CONFIG_KIND, "groups").to(GroupsCollection.class); - } - }); - bind(LifecycleListener.class) - .annotatedWith(UniqueAnnotations.create()) - .to(ImportLog.class); + child(CONFIG_KIND, "groups").to(GroupsCollection.class); + } + }); + bind(LifecycleListener.class).annotatedWith(UniqueAnnotations.create()).to(ImportLog.class); bind(OpenRepositoryStep.class); bind(ConfigureRepositoryStep.class); bind(ConfigureProjectStep.class);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/OpenRepositoryStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/OpenRepositoryStep.java index 06fb06c..16f63d6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/OpenRepositoryStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/OpenRepositoryStep.java
@@ -31,23 +31,21 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; - +import java.io.IOException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Repository; -import java.io.IOException; - @Singleton class OpenRepositoryStep { private final GitRepositoryManager git; private final ProjectCache projectCache; - private final DynamicSet<ProjectCreationValidationListener> - projectCreationValidationListeners; + private final DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners; private final Provider<ProjectsCollection> projectsCollection; @Inject - OpenRepositoryStep(GitRepositoryManager git, + OpenRepositoryStep( + GitRepositoryManager git, ProjectCache projectCache, DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners, Provider<ProjectsCollection> projectsCollection) { @@ -57,23 +55,20 @@ this.projectsCollection = projectsCollection; } - Repository open(Project.NameKey name, boolean resume, ProgressMonitor pm, - Project.NameKey parent) + Repository open(Project.NameKey name, boolean resume, ProgressMonitor pm, Project.NameKey parent) throws ResourceConflictException, IOException, UnprocessableEntityException, - PermissionBackendException { + PermissionBackendException { pm.beginTask("Open repository", 1); try { Repository repo = git.openRepository(name); if (resume) { return repo; } - throw new ResourceConflictException(format( - "repository %s already exists", name.get())); + throw new ResourceConflictException(format("repository %s already exists", name.get())); } catch (RepositoryNotFoundException e) { // Project doesn't exist if (resume) { - throw new ResourceConflictException(format( - "repository %s does not exist", name.get())); + throw new ResourceConflictException(format("repository %s does not exist", name.get())); } } @@ -86,7 +81,7 @@ private void beforeCreateProject(Project.NameKey name, Project.NameKey parent) throws ResourceConflictException, UnprocessableEntityException, IOException, - PermissionBackendException { + PermissionBackendException { CreateProjectArgs args = new CreateProjectArgs(); args.setProjectName(name); args.newParent = projectsCollection.get().parse(parent.get()).getNameKey();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/PasswordUtil.java b/src/main/java/com/googlesource/gerrit/plugins/importer/PasswordUtil.java index 6409e72..f4705b3 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/PasswordUtil.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/PasswordUtil.java
@@ -18,7 +18,6 @@ import com.google.common.base.Strings; import com.google.gerrit.sshd.BaseCommand.UnloggedFailure; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -30,8 +29,7 @@ static String readPassword(InputStream in, String pass) throws UnsupportedEncodingException, IOException, UnloggedFailure { if ("-".equals(pass)) { - BufferedReader br = new BufferedReader( - new InputStreamReader(in, UTF_8)); + BufferedReader br = new BufferedReader(new InputStreamReader(in, UTF_8)); pass = Strings.nullToEmpty(br.readLine()); if (br.readLine() != null) { throw new UnloggedFailure(1, "multi-line password not allowed");
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java index d55bb4c..f69eb9d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectCommand.java
@@ -20,61 +20,81 @@ import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.server.config.ConfigResource; -import com.google.gerrit.server.update.UpdateException; +import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.project.NoSuchChangeException; +import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.validators.ValidationException; import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; - +import java.io.IOException; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.errors.ConfigInvalidException; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; -import java.io.IOException; - @RequiresCapability(ImportCapability.ID) @CommandMetaData(name = "project", description = "Imports a project") public class ProjectCommand extends SshCommand { - @Option(name = "--from", aliases = {"-f"}, required = true, metaVar = "URL", + @Option( + name = "--from", + aliases = {"-f"}, + required = true, + metaVar = "URL", usage = "URL of the remote system from where the project should be imported") private String url; - @Option(name = "--name", required = false, metaVar = "NAME", - usage = "name of project in source system (if not specified it is" - + " assumed to be the same name as in the target system)") + @Option( + name = "--name", + required = false, + metaVar = "NAME", + usage = + "name of project in source system (if not specified it is" + + " assumed to be the same name as in the target system)") private String name; - @Option(name = "--user", aliases = {"-u"}, required = true, metaVar = "NAME", + @Option( + name = "--user", + aliases = {"-u"}, + required = true, + metaVar = "NAME", usage = "user on remote system") private String user; - @Option(name = "--pass", aliases = {"-p"}, required = true, metaVar = "-|PASS", + @Option( + name = "--pass", + aliases = {"-p"}, + required = true, + metaVar = "-|PASS", usage = "password of remote user") private String pass; - @Option(name = "--parent", required = false, metaVar = "NAME", + @Option( + name = "--parent", + required = false, + metaVar = "NAME", usage = "name of parent project in target system") private String parent; @Option(name = "--quiet", usage = "suppress progress messages") private boolean quiet; - @Argument(index = 0, required = true, metaVar = "NAME", + @Argument( + index = 0, + required = true, + metaVar = "NAME", usage = "name of the project in target system") private String project; - @Inject - private ImportProject.Factory importProjectFactory; + @Inject private ImportProject.Factory importProjectFactory; @Override protected void run() - throws OrmException, IOException, UnloggedFailure, ValidationException, - GitAPIException, NoSuchChangeException, NoSuchAccountException, - UpdateException, ConfigInvalidException, PermissionBackendException { + throws OrmException, IOException, UnloggedFailure, ValidationException, GitAPIException, + NoSuchChangeException, NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { ImportProject.Input input = new ImportProject.Input(); input.from = url; input.name = name;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectsCollection.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectsCollection.java index ded7130..cb50841 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectsCollection.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ProjectsCollection.java
@@ -30,16 +30,15 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; - import java.io.File; import java.io.IOException; import java.nio.file.Path; @Singleton @RequiresCapability(ImportCapability.ID) -public class ProjectsCollection implements - ChildCollection<ConfigResource, ImportProjectResource>, - AcceptsCreate<ConfigResource> { +public class ProjectsCollection + implements ChildCollection<ConfigResource, ImportProjectResource>, + AcceptsCreate<ConfigResource> { class FileSystemLayout { @@ -54,39 +53,40 @@ } String resolveProjectName(File f) throws IOException { - if(! f.isFile()) { - throw new RuntimeException(format("'%s' is not a file. Project names" - + "can only be resolved for existing files, not for directories." - , f)); + if (!f.isFile()) { + throw new RuntimeException( + format( + "'%s' is not a file. Project names" + + "can only be resolved for existing files, not for directories.", + f)); } - if(! f.getName().endsWith(SUFFIX_IMPORT_STATUS_FILE)) { - throw new RuntimeException(format("'%s' is not a valid import status" - + "file. Invalid appendix. Should be '%s'.", f, - SUFFIX_IMPORT_STATUS_FILE)); + if (!f.getName().endsWith(SUFFIX_IMPORT_STATUS_FILE)) { + throw new RuntimeException( + format( + "'%s' is not a valid import status" + "file. Invalid appendix. Should be '%s'.", + f, SUFFIX_IMPORT_STATUS_FILE)); } String diff = diff(lockRoot, f); - return diff.substring(0, diff.length() - - SUFFIX_IMPORT_STATUS_FILE.length()); + return diff.substring(0, diff.length() - SUFFIX_IMPORT_STATUS_FILE.length()); } /** - * Returns the path between two file instances. The child instance - * is expected to be a child of the parent instance. + * Returns the path between two file instances. The child instance is expected to be a child of + * the parent instance. + * * @param parent * @param child * @return The path between parent and child. - * @throws IOException in case <code>child</code> is not a child of - * <code>parent</code>. + * @throws IOException in case <code>child</code> is not a child of <code>parent</code>. */ private String diff(File parent, File child) throws IOException { Path parentPath = parent.getAbsoluteFile().toPath(); - Path childPath= child.getAbsoluteFile().toPath(); + Path childPath = child.getAbsoluteFile().toPath(); if (childPath.startsWith(parentPath)) { return parentPath.relativize(childPath).toString(); } - throw new IOException(String.format("'%s' is not a child of '%s'.", - child, parent)); + throw new IOException(String.format("'%s' is not a child of '%s'.", child, parent)); } } @@ -120,8 +120,7 @@ return parse(id.get()); } - public ImportProjectResource parse(String id) - throws ResourceNotFoundException { + public ImportProjectResource parse(String id) throws ResourceNotFoundException { File f = FS_LAYOUT.getImportStatusFile(id); if (!f.exists()) { throw new ResourceNotFoundException(id); @@ -136,8 +135,7 @@ } @Override - public ImportProject create(ConfigResource parent, IdString id) - throws RestApiException { + public ImportProject create(ConfigResource parent, IdString id) throws RestApiException { return importProjectFactory.create(new Project.NameKey(id.get())); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/RemoteApi.java b/src/main/java/com/googlesource/gerrit/plugins/importer/RemoteApi.java index b83a142..061341e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/RemoteApi.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/RemoteApi.java
@@ -28,14 +28,12 @@ import com.google.gerrit.server.OutputFormat; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; - -import org.apache.http.HttpStatus; - import java.io.IOException; import java.net.UnknownHostException; import java.util.EnumSet; import java.util.List; import java.util.Map; +import org.apache.http.HttpStatus; class RemoteApi implements GerritApi { @@ -46,35 +44,37 @@ } @Override - public ProjectInfo getProject(String projectName) throws IOException, - BadRequestException { + public ProjectInfo getProject(String projectName) throws IOException, BadRequestException { projectName = encode(projectName); String endPoint = "/projects/" + projectName; try (RestResponse r = checkedGet(endPoint)) { - return newGson().fromJson(r.getReader(), - new TypeToken<ProjectInfo>() {}.getType()); + return newGson().fromJson(r.getReader(), new TypeToken<ProjectInfo>() {}.getType()); } } @Override - public List<ChangeInfo> queryChanges(String projectName, - int start, int limit) throws IOException, BadRequestException { + public List<ChangeInfo> queryChanges(String projectName, int start, int limit) + throws IOException, BadRequestException { String endPoint = - "/changes/?S=" + - start + ((limit > 0) ? "&n=" + limit : "") + "&q=project:" + projectName + - "&O=" + Integer.toHexString(ListChangesOption.toBits( - EnumSet.of( - ListChangesOption.DETAILED_LABELS, - ListChangesOption.DETAILED_ACCOUNTS, - ListChangesOption.MESSAGES, - ListChangesOption.CURRENT_REVISION, - ListChangesOption.ALL_REVISIONS, - ListChangesOption.ALL_COMMITS))); + "/changes/?S=" + + start + + ((limit > 0) ? "&n=" + limit : "") + + "&q=project:" + + projectName + + "&O=" + + Integer.toHexString( + ListChangesOption.toBits( + EnumSet.of( + ListChangesOption.DETAILED_LABELS, + ListChangesOption.DETAILED_ACCOUNTS, + ListChangesOption.MESSAGES, + ListChangesOption.CURRENT_REVISION, + ListChangesOption.ALL_REVISIONS, + ListChangesOption.ALL_COMMITS))); List<ChangeInfo> result; try (RestResponse r = checkedGet(endPoint)) { - result = newGson().fromJson(r.getReader(), - new TypeToken<List<ChangeInfo>>() {}.getType()); + result = newGson().fromJson(r.getReader(), new TypeToken<List<ChangeInfo>>() {}.getType()); } for (ChangeInfo c : result) { @@ -87,13 +87,11 @@ } @Override - public GroupInfo getGroup(String groupName) throws IOException, - BadRequestException { + public GroupInfo getGroup(String groupName) throws IOException, BadRequestException { groupName = encode(groupName); String endPoint = "/groups/" + groupName + "/detail"; try (RestResponse r = checkedGet(endPoint)) { - return newGson().fromJson(r.getReader(), - new TypeToken<GroupInfo>() {}.getType()); + return newGson().fromJson(r.getReader(), new TypeToken<GroupInfo>() {}.getType()); } } @@ -107,8 +105,10 @@ return null; } assertOK(HttpMethod.GET, endPoint, r); - result = newGson().fromJson(r.getReader(), - new TypeToken<Map<String, List<CommentInfo>>>() {}.getType()); + result = + newGson() + .fromJson( + r.getReader(), new TypeToken<Map<String, List<CommentInfo>>>() {}.getType()); } for (Map.Entry<String, List<CommentInfo>> e : result.entrySet()) { for (CommentInfo i : e.getValue()) { @@ -122,8 +122,7 @@ public List<SshKeyInfo> getSshKeys(String userId) throws BadRequestException, IOException { String endPoint = "/accounts/" + userId + "/sshkeys/"; try (RestResponse r = checkedGet(endPoint)) { - return newGson().fromJson(r.getReader(), - new TypeToken<List<SshKeyInfo>>() {}.getType()); + return newGson().fromJson(r.getReader(), new TypeToken<List<SshKeyInfo>>() {}.getType()); } } @@ -131,8 +130,8 @@ public Version getVersion() throws BadRequestException, IOException { String endPoint = "/config/server/version"; try (RestResponse r = checkedGet(endPoint)) { - return new Version((String)newGson().fromJson( - r.getReader(), new TypeToken<String>() {}.getType())); + return new Version( + (String) newGson().fromJson(r.getReader(), new TypeToken<String>() {}.getType())); } } @@ -140,8 +139,7 @@ return OutputFormat.JSON_COMPACT.newGson(); } - private RestResponse checkedGet(String endPoint) throws IOException, - BadRequestException { + private RestResponse checkedGet(String endPoint) throws IOException, BadRequestException { try { RestResponse r = restSession.get(endPoint); assertOK(HttpMethod.GET, endPoint, r); @@ -151,22 +149,25 @@ } } - private static void assertOK(HttpMethod method, String endPoint, - RestResponse r) throws IOException, BadRequestException { + private static void assertOK(HttpMethod method, String endPoint, RestResponse r) + throws IOException, BadRequestException { if (r.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new BadRequestException( "invalid credentials: accessing source system failed with 401 Unauthorized"); } if (r.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - throw new BadRequestException(String.format( - "missing permissions or invalid import entity identifier: Accessing " - + "REST endpoint %s on source system failed with 404 Not found", endPoint)); + throw new BadRequestException( + String.format( + "missing permissions or invalid import entity identifier: Accessing " + + "REST endpoint %s on source system failed with 404 Not found", + endPoint)); } if (r.getStatusCode() < 200 || 300 <= r.getStatusCode()) { - throw new IOException(String.format( - "Unexpected response code for %s on %s : %s", method.name(), - endPoint, r.getStatusCode())); + throw new IOException( + String.format( + "Unexpected response code for %s on %s : %s", + method.name(), endPoint, r.getStatusCode())); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java index 8cc0c83..ab106a6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayChangesStep.java
@@ -18,38 +18,36 @@ import com.google.gerrit.common.Nullable; import com.google.gerrit.common.data.GlobalCapability; import com.google.gerrit.common.errors.NoSuchAccountException; -import com.google.gerrit.extensions.client.ChangeStatus; import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.Url; import com.google.gerrit.reviewdb.client.Branch; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Project; +import com.google.gerrit.reviewdb.client.RefNames; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.Sequences; -import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.index.change.ChangeIndexer; import com.google.gerrit.server.notedb.NotesMigration; +import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.InternalChangeQuery; +import com.google.gerrit.server.update.UpdateException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.assistedinject.Assisted; - +import java.io.IOException; +import java.util.Collections; +import java.util.List; import org.eclipse.jgit.errors.ConfigInvalidException; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevWalk; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.Collections; -import java.util.List; - class ReplayChangesStep { interface Factory { @@ -135,16 +133,16 @@ this.isNoteDbEnabled = migration.readChanges(); } - void replay() throws IOException, OrmException, - NoSuchAccountException, NoSuchChangeException, RestApiException, - UpdateException, ConfigInvalidException { + void replay() + throws IOException, OrmException, NoSuchAccountException, NoSuchChangeException, + RestApiException, UpdateException, ConfigInvalidException, + PatchListNotAvailableException { int start = 0; int limit = GlobalCapability.DEFAULT_MAX_QUERY_LIMIT; pm.beginTask("Replay Changes", ProgressMonitor.UNKNOWN); - for(;;) { - List<ChangeInfo> changes = api.queryChanges(srcProject.get(), - start, limit); - if(changes.isEmpty()) { + for (; ; ) { + List<ChangeInfo> changes = api.queryChanges(srcProject.get(), start, limit); + if (changes.isEmpty()) { break; } start += changes.size(); @@ -154,14 +152,13 @@ try { replayChange(rw, c); } catch (Exception e) { - log.error(String.format("Failed to replay change %s.", - Url.decode(c.id)), e); + log.error(String.format("Failed to replay change %s.", Url.decode(c.id)), e); throw e; } last = c; pm.update(1); } - if(!Boolean.TRUE.equals(last._moreChanges)) { + if (!Boolean.TRUE.equals(last._moreChanges)) { break; } } @@ -170,9 +167,9 @@ } private void replayChange(RevWalk rw, ChangeInfo c) - throws IOException, OrmException, NoSuchAccountException, - NoSuchChangeException, RestApiException, IllegalArgumentException, - UpdateException, ConfigInvalidException { + throws IOException, OrmException, NoSuchAccountException, NoSuchChangeException, + RestApiException, IllegalArgumentException, UpdateException, ConfigInvalidException, + PatchListNotAvailableException { Change change = resume ? findChange(c) : null; boolean resumeChange; if (change == null) { @@ -213,33 +210,38 @@ } private Change findChange(ChangeInfo c) throws OrmException { - List<Change> changes = ChangeData.asChanges( - queryProvider.get().byBranchKey( - new Branch.NameKey(targetProject, fullName(c.branch)), - new Change.Key(c.changeId))); + List<Change> changes = + ChangeData.asChanges( + queryProvider + .get() + .byBranchKey( + new Branch.NameKey(targetProject, RefNames.fullName(c.branch)), + new Change.Key(c.changeId))); if (changes.isEmpty()) { return null; } - return db.changes().get( - Iterators.getOnlyElement(changes.iterator()).getId()); + return db.changes().get(Iterators.getOnlyElement(changes.iterator()).getId()); } private Change createChange(ChangeInfo c) - throws OrmException, NoSuchAccountException, IOException, - RestApiException, ConfigInvalidException { + throws OrmException, NoSuchAccountException, IOException, RestApiException, + ConfigInvalidException { Change.Id changeId = new Change.Id(sequences.nextChangeId()); Change change = - new Change(new Change.Key(c.changeId), changeId, accountUtil.resolveUser(api, c.owner), - new Branch.NameKey(targetProject, fullName(c.branch)), c.created); + new Change( + new Change.Key(c.changeId), + changeId, + accountUtil.resolveUser(api, c.owner), + new Branch.NameKey(targetProject, RefNames.fullName(c.branch)), + c.created); change.setStatus(Change.Status.forChangeStatus(c.status)); change.setTopic(c.topic); change.setLastUpdatedOn(c.updated); return change; } - private void upsertChange(boolean resumeChange, Change change, ChangeInfo c) - throws OrmException { + private void upsertChange(boolean resumeChange, Change change, ChangeInfo c) throws OrmException { if (resumeChange) { change.setStatus(Change.Status.forChangeStatus(c.status)); change.setTopic(c.topic); @@ -247,11 +249,4 @@ } db.changes().upsert(Collections.singleton(change)); } - - private static String fullName(String branch) { - if (branch.startsWith(Constants.R_HEADS)) { - return branch; - } - return Constants.R_HEADS + branch; - } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java index ec1062c..4895861 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
@@ -41,18 +41,14 @@ import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.PatchSetUtil; import com.google.gerrit.server.config.GerritServerId; +import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeUpdate; import com.google.gerrit.server.patch.PatchListCache; -import com.google.gerrit.server.project.ChangeControl; +import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; - -import org.eclipse.jgit.errors.ConfigInvalidException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.util.Collection; import java.util.HashSet; @@ -60,21 +56,23 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; class ReplayInlineCommentsStep { interface Factory { - ReplayInlineCommentsStep create(Change change, ChangeInfo changeInfo, - GerritApi api, boolean resume); + ReplayInlineCommentsStep create( + Change change, ChangeInfo changeInfo, GerritApi api, boolean resume); } - private static final Logger log = LoggerFactory - .getLogger(ReplayInlineCommentsStep.class); + private static final Logger log = LoggerFactory.getLogger(ReplayInlineCommentsStep.class); private final AccountUtil accountUtil; private final ReviewDb db; private final IdentifiedUser.GenericFactory genericUserFactory; - private final ChangeControl.GenericFactory changeControlFactory; + private final ChangeNotes.Factory changeNotesFactory; private final ChangeUpdate.Factory updateFactory; private final CommentsUtil commentsUtil; private final PatchListCache patchListCache; @@ -86,10 +84,11 @@ private final boolean resume; @Inject - public ReplayInlineCommentsStep(AccountUtil accountUtil, + public ReplayInlineCommentsStep( + AccountUtil accountUtil, ReviewDb db, IdentifiedUser.GenericFactory genericUserFactory, - ChangeControl.GenericFactory changeControlFactory, + ChangeNotes.Factory changeNotesFactory, ChangeUpdate.Factory updateFactory, CommentsUtil commentsUtil, PatchListCache patchListCache, @@ -102,7 +101,7 @@ this.accountUtil = accountUtil; this.db = db; this.genericUserFactory = genericUserFactory; - this.changeControlFactory = changeControlFactory; + this.changeNotesFactory = changeNotesFactory; this.updateFactory = updateFactory; this.commentsUtil = commentsUtil; this.patchListCache = patchListCache; @@ -116,39 +115,38 @@ void replay() throws RestApiException, OrmException, IOException, NoSuchChangeException, - NoSuchAccountException, ConfigInvalidException { - ChangeControl ctrl = control(change, change.getOwner()); - for (PatchSet ps : ChangeUtil.PS_ID_ORDER - .sortedCopy(psUtil.byChange(db, ctrl.getNotes()))) { - Iterable<CommentInfo> comments = api.getComments( - changeInfo._number, ps.getRevision().get()); + NoSuchAccountException, ConfigInvalidException, PatchListNotAvailableException { + ChangeNotes notes = changeNotesFactory.createChecked(db, change); + for (PatchSet ps : ChangeUtil.PS_ID_ORDER.sortedCopy(psUtil.byChange(db, notes))) { + Iterable<CommentInfo> comments = api.getComments(changeInfo._number, ps.getRevision().get()); if (resume) { if (comments == null) { // the revision does not exist in the source system, // it must be a revision that was created in the target system after // the initial import - log.warn(String.format( - "Project %s was modified in target system: " - + "Skip replay inline comments for patch set %s" - + " which doesn't exist in the source system.", - change.getProject().get(), ps.getId().toString())); + log.warn( + String.format( + "Project %s was modified in target system: " + + "Skip replay inline comments for patch set %s" + + " which doesn't exist in the source system.", + change.getProject().get(), ps.getId().toString())); continue; } comments = filterComments(ps, comments); } else if (comments == null) { - log.warn(String.format( - "Cannot retrieve comments for revision %s, " - + "revision not found in source system: " - + "Skip replay inline comments for patch set %s of project %s.", - ps.getRevision().get(), ps.getId().toString(), - change.getProject().get())); + log.warn( + String.format( + "Cannot retrieve comments for revision %s, " + + "revision not found in source system: " + + "Skip replay inline comments for patch set %s of project %s.", + ps.getRevision().get(), ps.getId().toString(), change.getProject().get())); continue; } Multimap<Account.Id, CommentInfo> commentsByAuthor = ArrayListMultimap.create(); for (CommentInfo comment : comments) { - Account.Id id = accountUtil.resolveUser(api, comment.author); + Account.Id id = accountUtil.resolveUser(api, comment.author); commentsByAuthor.put(id, comment); } @@ -158,8 +156,8 @@ } } - private Iterable<CommentInfo> filterComments(PatchSet ps, - Iterable<CommentInfo> comments) throws OrmException { + private Iterable<CommentInfo> filterComments(PatchSet ps, Iterable<CommentInfo> comments) + throws OrmException { Set<String> existingUuids = new HashSet<>(); for (PatchLineComment c : db.patchComments().byPatchSet(ps.getId())) { existingUuids.add(c.getKey().get()); @@ -175,12 +173,11 @@ return comments; } - private void insertComments(PatchSet ps, Account.Id author, - Collection<CommentInfo> comments) throws OrmException, IOException, - NoSuchChangeException { - ChangeControl ctrl = control(change, author); + private void insertComments(PatchSet ps, Account.Id author, Collection<CommentInfo> comments) + throws OrmException, IOException, NoSuchChangeException, PatchListNotAvailableException { + ChangeNotes notes = changeNotesFactory.createChecked(db, change); - Map<String, Comment> drafts = scanDraftComments(ctrl, ps); + Map<String, Comment> drafts = scanDraftComments(notes, ps, author); List<Comment> del = Lists.newArrayList(); List<Comment> ups = Lists.newArrayList(); @@ -190,8 +187,9 @@ Comment e = drafts.remove(Url.decode(c.id)); if (e == null) { - e = new Comment( - new Comment.Key(Url.decode(c.id), c.path, ps.getId().get()), + e = + new Comment( + new Comment.Key(Url.decode(c.id), c.path, ps.getId().get()), author, c.updated, c.side == Side.PARENT ? (short) 0 : (short) 1, @@ -203,18 +201,19 @@ } setCommentRevId(e, patchListCache, change, ps); if (c.range != null) { - e.setRange(new CommentRange( - c.range.startLine, - c.range.startCharacter, - c.range.endLine, - c.range.endCharacter)); + e.setRange( + new CommentRange( + c.range.startLine, c.range.startCharacter, c.range.endLine, c.range.endCharacter)); e.lineNbr = c.range.endLine; + } else { + e.lineNbr = c.line == null ? 0 : c.line; } ups.add(e); } Iterables.addAll(del, drafts.values()); - ChangeUpdate update = updateFactory.create(ctrl.getNotes(), ctrl.getUser(), TimeUtil.nowTs()); + ChangeUpdate update = + updateFactory.create(notes, genericUserFactory.create(author), TimeUtil.nowTs()); update.setPatchSetId(ps.getId()); commentsUtil.deleteComments(db, update, del); @@ -222,24 +221,12 @@ update.commit(); } - private Map<String, Comment> scanDraftComments(ChangeControl ctrl, - PatchSet ps) throws OrmException { + private Map<String, Comment> scanDraftComments(ChangeNotes notes, PatchSet ps, Account.Id account) + throws OrmException { Map<String, Comment> drafts = Maps.newHashMap(); - for (Comment c : commentsUtil.draftByPatchSetAuthor(db, ps.getId(), - ((IdentifiedUser) ctrl.getUser()).getAccountId(), - ctrl.getNotes())) { + for (Comment c : commentsUtil.draftByPatchSetAuthor(db, ps.getId(), account, notes)) { drafts.put(c.key.uuid, c); } return drafts; } - - private ChangeControl control(Change change, Account.Id id) - throws NoSuchChangeException { - try { - return changeControlFactory.controlFor(db, change, - genericUserFactory.create(id)); - } catch (OrmException e) { - throw new NoSuchChangeException(change.getId()); - } - } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java index 9b1d130..98186f5 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayMessagesStep.java
@@ -24,25 +24,23 @@ import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.ChangeMessagesUtil; +import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; +import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeUpdate; -import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; - -import org.eclipse.jgit.errors.ConfigInvalidException; - import java.io.IOException; import java.sql.Timestamp; import java.util.Collections; +import org.eclipse.jgit.errors.ConfigInvalidException; class ReplayMessagesStep { interface Factory { - ReplayMessagesStep create(Change change, ChangeInfo changeInfo, - boolean resume); + ReplayMessagesStep create(Change change, ChangeInfo changeInfo, boolean resume); } private final AccountUtil accountUtil; @@ -50,17 +48,18 @@ private final ChangeMessagesUtil cmUtil; private final ReviewDb db; private final IdentifiedUser.GenericFactory genericUserFactory; - private final ChangeControl.GenericFactory changeControlFactory; + private final ChangeNotes.Factory changeNotesFactory; private final Change change; private final ChangeInfo changeInfo; private final boolean resume; @Inject - public ReplayMessagesStep(AccountUtil accountUtil, + public ReplayMessagesStep( + AccountUtil accountUtil, ChangeUpdate.Factory updateFactory, ChangeMessagesUtil cmUtil, IdentifiedUser.GenericFactory genericUserFactory, - ChangeControl.GenericFactory changeControlFactory, + ChangeNotes.Factory changeNotesFactory, ReviewDb db, @Assisted Change change, @Assisted ChangeInfo changeInfo, @@ -70,15 +69,15 @@ this.cmUtil = cmUtil; this.db = db; this.genericUserFactory = genericUserFactory; - this.changeControlFactory = changeControlFactory; + this.changeNotesFactory = changeNotesFactory; this.change = change; this.changeInfo = changeInfo; this.resume = resume; } - void replay(GerritApi api) throws NoSuchAccountException, - NoSuchChangeException, OrmException, IOException, RestApiException, - ConfigInvalidException { + void replay(GerritApi api) + throws NoSuchAccountException, NoSuchChangeException, OrmException, IOException, + RestApiException, ConfigInvalidException { for (ChangeMessageInfo msg : changeInfo.messages) { ChangeMessage.Key msgKey = new ChangeMessage.Key(change.getId(), msg.id); if (resume && db.changeMessages().get(msgKey) != null) { @@ -87,13 +86,13 @@ } Timestamp ts = msg.date; - PatchSet.Id psId = msg._revisionNumber != null - ? new PatchSet.Id(change.getId(), msg._revisionNumber) - : null; + PatchSet.Id psId = + msg._revisionNumber != null ? new PatchSet.Id(change.getId(), msg._revisionNumber) : null; if (msg.author != null) { Account.Id userId = accountUtil.resolveUser(api, msg.author); - ChangeControl ctrl = control(change, userId); - ChangeUpdate update = updateFactory.create(ctrl.getNotes(), ctrl.getUser(), ts); + ChangeNotes notes = changeNotesFactory.createChecked(db, change); + CurrentUser user = genericUserFactory.create(userId); + ChangeUpdate update = updateFactory.create(notes, user, ts); ChangeMessage cmsg = new ChangeMessage(msgKey, userId, ts, psId); cmsg.setMessage(msg.message); cmUtil.addChangeMessage(db, update, cmsg); @@ -101,21 +100,10 @@ } else { // Message create by the GerritPersonIdent user ChangeMessage cmsg = - new ChangeMessage(new ChangeMessage.Key(change.getId(), msg.id), - null, ts, psId); + new ChangeMessage(new ChangeMessage.Key(change.getId(), msg.id), null, ts, psId); cmsg.setMessage(msg.message); db.changeMessages().insert(Collections.singleton(cmsg)); } } } - - private ChangeControl control(Change change, Account.Id id) - throws NoSuchChangeException { - try { - return changeControlFactory.controlFor(db, change, - genericUserFactory.create(id)); - } catch (OrmException e) { - throw new NoSuchChangeException(change.getId()); - } - } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java index d98df7d..be52f2d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java
@@ -27,7 +27,9 @@ import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; - +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -38,19 +40,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - class ReplayRevisionsStep { interface Factory { - ReplayRevisionsStep create(Repository repo, RevWalk rw, Change change, - ChangeInfo changeInfo); + ReplayRevisionsStep create(Repository repo, RevWalk rw, Change change, ChangeInfo changeInfo); } - private static final Logger log = LoggerFactory - .getLogger(ReplayRevisionsStep.class); + private static final Logger log = LoggerFactory.getLogger(ReplayRevisionsStep.class); private final AccountUtil accountUtil; private final ReviewDb db; @@ -61,7 +57,8 @@ private final ChangeInfo changeInfo; @Inject - public ReplayRevisionsStep(AccountUtil accountUtil, + public ReplayRevisionsStep( + AccountUtil accountUtil, ReviewDb db, PatchSetInfoFactory patchSetInfoFactory, @Assisted Repository repo, @@ -78,8 +75,8 @@ } void replay(GerritApi api) - throws IOException, OrmException, NoSuchAccountException, - RestApiException, ConfigInvalidException { + throws IOException, OrmException, NoSuchAccountException, RestApiException, + ConfigInvalidException { List<RevisionInfo> revisions = new ArrayList<>(changeInfo.revisions.values()); sortRevisionInfoByNumber(revisions); List<PatchSet> patchSets = new ArrayList<>(); @@ -105,10 +102,11 @@ } // a patch set with the same number was created both in the source // and in the target system - log.warn(String.format( - "Project %s was modified in target system: " - + "Skip replay revision for patch set %s.", - change.getProject().get(), ps.getId().toString())); + log.warn( + String.format( + "Project %s was modified in target system: " + + "Skip replay revision for patch set %s.", + change.getProject().get(), ps.getId().toString())); continue; } @@ -128,15 +126,17 @@ if (change.currentPatchSetId() == null) { if (changeInfo.currentRevision != null) { - log.warn(String.format( - "Current revision %s of change %s not found." - + " Setting lastest revision %s as current patch set.", - changeInfo.currentRevision, changeInfo.id, info.getRevId())); + log.warn( + String.format( + "Current revision %s of change %s not found." + + " Setting lastest revision %s as current patch set.", + changeInfo.currentRevision, changeInfo.id, info.getRevId())); } else { - log.warn(String.format( - "Change %s has no current revision." - + " Setting lastest revision %s as current patch set.", - changeInfo.id, info.getRevId())); + log.warn( + String.format( + "Change %s has no current revision." + + " Setting lastest revision %s as current patch set.", + changeInfo.id, info.getRevId())); } change.setCurrentPatchSet(info); } @@ -149,16 +149,14 @@ } private static String imported(String ref) { - return ConfigureRepositoryStep.R_IMPORTS - + ref.substring(Constants.R_REFS.length()); + return ConfigureRepositoryStep.R_IMPORTS + ref.substring(Constants.R_REFS.length()); } private static void sortRevisionInfoByNumber(List<RevisionInfo> list) { list.sort((a, b) -> a._number - b._number); } - private void updateRef(Repository repo, PatchSet ps) - throws IOException { + private void updateRef(Repository repo, PatchSet ps) throws IOException { String ref = ps.getId().toRefName(); RefUpdate ru = repo.updateRef(ref); ru.setExpectedOldObjectId(ObjectId.zeroId()); @@ -179,8 +177,8 @@ case REJECTED_MISSING_OBJECT: case REJECTED_OTHER_REASON: default: - throw new IOException(String.format( - "Failed to create ref %s, RefUpdate.Result = %s", ref, result)); + throw new IOException( + String.format("Failed to create ref %s, RefUpdate.Result = %s", ref, result)); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/RestResponse.java b/src/main/java/com/googlesource/gerrit/plugins/importer/RestResponse.java index 24f6831..27ca570 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/RestResponse.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/RestResponse.java
@@ -16,11 +16,10 @@ import static com.google.gerrit.httpd.restapi.RestApiServlet.JSON_MAGIC; -import org.apache.http.client.methods.CloseableHttpResponse; - import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import org.apache.http.client.methods.CloseableHttpResponse; public class RestResponse extends HttpResponse {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/RestSession.java b/src/main/java/com/googlesource/gerrit/plugins/importer/RestSession.java index d2ca5c7..39e5c38 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/RestSession.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/RestSession.java
@@ -18,7 +18,10 @@ import com.google.common.base.Preconditions; import com.google.gerrit.extensions.restapi.RawInput; import com.google.gerrit.server.OutputFormat; - +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; @@ -28,11 +31,6 @@ import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHeader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; - public class RestSession extends HttpSession { public RestSession(String url, String user, String pass) { @@ -53,9 +51,9 @@ HttpPut put = new HttpPut(url + "/a" + endPoint); if (content != null) { put.addHeader(new BasicHeader("Content-Type", "application/json")); - put.setEntity(new StringEntity( - OutputFormat.JSON_COMPACT.newGson().toJson(content), - Charsets.UTF_8.name())); + put.setEntity( + new StringEntity( + OutputFormat.JSON_COMPACT.newGson().toJson(content), Charsets.UTF_8.name())); } return new RestResponse(getClient().execute(put)); } @@ -64,10 +62,9 @@ Preconditions.checkNotNull(stream); HttpPut put = new HttpPut(url + "/a" + endPoint); put.addHeader(new BasicHeader("Content-Type", stream.getContentType())); - put.setEntity(new BufferedHttpEntity( - new InputStreamEntity( - stream.getInputStream(), - stream.getContentLength()))); + put.setEntity( + new BufferedHttpEntity( + new InputStreamEntity(stream.getInputStream(), stream.getContentLength()))); return new RestResponse(getClient().execute(put)); } @@ -79,9 +76,9 @@ HttpPost post = new HttpPost(url + "/a" + endPoint); if (content != null) { post.addHeader(new BasicHeader("Content-Type", "application/json")); - post.setEntity(new StringEntity( - OutputFormat.JSON_COMPACT.newGson().toJson(content), - Charsets.UTF_8.name())); + post.setEntity( + new StringEntity( + OutputFormat.JSON_COMPACT.newGson().toJson(content), Charsets.UTF_8.name())); } return new RestResponse(getClient().execute(post)); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyCommand.java index fa70cba..17f186e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyCommand.java
@@ -23,7 +23,6 @@ import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; import com.google.inject.Inject; - import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -37,22 +36,18 @@ @Option(name = "--quiet", usage = "suppress progress messages") private boolean quiet; - @Argument(index = 0, required = true, metaVar = "NAME", - usage = "name of the target project") + @Argument(index = 0, required = true, metaVar = "NAME", usage = "name of the target project") private String project; - @Inject - private ResumeCopyProject resume; + @Inject private ResumeCopyProject resume; - @Inject - private ProjectsCollection projects; + @Inject private ProjectsCollection projects; @Override protected void run() throws UnloggedFailure, Failure, Exception { try { ProjectResource rsrc = - projects.parse(TopLevelResource.INSTANCE, - IdString.fromDecoded(project)); + projects.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(project)); if (!quiet) { resume.setErr(stderr); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java index ae6ed9f..0b85b8f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeCopyProject.java
@@ -28,28 +28,26 @@ import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.config.ConfigResource; -import com.google.gerrit.server.update.UpdateException; +import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.permissions.PermissionBackend; import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectResource; +import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.validators.ValidationException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; - import com.googlesource.gerrit.plugins.importer.ResumeCopyProject.Input; - +import java.io.IOException; +import java.io.Writer; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.errors.ConfigInvalidException; -import java.io.IOException; -import java.io.Writer; - @RequiresCapability(CopyProjectCapability.ID) -class ResumeCopyProject implements RestModifyView<ProjectResource, Input>, - UiAction<ProjectResource> { +class ResumeCopyProject + implements RestModifyView<ProjectResource, Input>, UiAction<ProjectResource> { public static class Input { public boolean force; } @@ -86,23 +84,18 @@ @Override public ResumeImportStatistic apply(ProjectResource rsrc, Input input) - throws RestApiException, IOException, OrmException, ValidationException, - GitAPIException, NoSuchChangeException, NoSuchAccountException, - UpdateException, ConfigInvalidException, PermissionBackendException { + throws RestApiException, IOException, OrmException, ValidationException, GitAPIException, + NoSuchChangeException, NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { ImportProjectResource projectResource = - projectsCollection.parse(new ConfigResource(), - IdString.fromDecoded(rsrc.getName())); + projectsCollection.parse(new ConfigResource(), IdString.fromDecoded(rsrc.getName())); ResumeProjectImport.Input in = new ResumeProjectImport.Input(); in.force = input.force; - return resumeProjectImport.get() - .setCopy(true) - .setErr(err) - .apply(projectResource, in); + return resumeProjectImport.get().setCopy(true).setErr(err).apply(projectResource, in); } @Override - public UiAction.Description getDescription( - ProjectResource rsrc) { + public UiAction.Description getDescription(ProjectResource rsrc) { return new UiAction.Description() .setLabel("Resume Copy...") .setTitle(String.format("Resume copy for project %s", rsrc.getName())) @@ -110,17 +103,17 @@ } private boolean canResumeCopy(ProjectResource rsrc) { - return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) || - (permissionBackend.user(currentUserProvider).testOrFalse( - new PluginPermission(pluginName, CopyProjectCapability.ID)) && - rsrc.getControl().isOwner()); + return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) + || (permissionBackend + .user(currentUserProvider) + .testOrFalse(new PluginPermission(pluginName, CopyProjectCapability.ID)) + && rsrc.getControl().isOwner()); } private boolean isCopied(ProjectResource rsrc) { try { ImportProjectResource projectResource = - projectsCollection.parse(new ConfigResource(), - IdString.fromDecoded(rsrc.getName())); + projectsCollection.parse(new ConfigResource(), IdString.fromDecoded(rsrc.getName())); ImportProjectInfo info = projectResource.getInfo(); if (info.from != null) { // no copy, but an import from another system
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java index fb2a4a4..c4fe6b3 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectCommand.java
@@ -19,7 +19,6 @@ import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; import com.google.inject.Inject; - import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -27,11 +26,19 @@ @CommandMetaData(name = "resume-project", description = "Resumes project import") public class ResumeProjectCommand extends SshCommand { - @Option(name = "--user", aliases = {"-u"}, required = true, metaVar = "NAME", + @Option( + name = "--user", + aliases = {"-u"}, + required = true, + metaVar = "NAME", usage = "user on remote system") private String user; - @Option(name = "--pass", aliases = {"-p"}, required = true, metaVar = "-|PASS", + @Option( + name = "--pass", + aliases = {"-p"}, + required = true, + metaVar = "-|PASS", usage = "password of remote user") private String pass; @@ -41,15 +48,16 @@ @Option(name = "--quiet", usage = "suppress progress messages") private boolean quiet; - @Argument(index = 0, required = true, metaVar = "NAME", + @Argument( + index = 0, + required = true, + metaVar = "NAME", usage = "name of the project in target system") private String project; - @Inject - private ResumeProjectImport resume; + @Inject private ResumeProjectImport resume; - @Inject - private ProjectsCollection projects; + @Inject private ProjectsCollection projects; @Override protected void run() throws UnloggedFailure, Failure, Exception {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java index 996c7e4..aa74c1c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ResumeProjectImport.java
@@ -29,23 +29,21 @@ import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.config.ConfigResource; -import com.google.gerrit.server.update.UpdateException; +import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.permissions.PermissionBackend; import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.ProjectResource; +import com.google.gerrit.server.update.UpdateException; import com.google.gerrit.server.validators.ValidationException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; - import com.googlesource.gerrit.plugins.importer.ResumeProjectImport.Input; - -import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.errors.ConfigInvalidException; - import java.io.IOException; import java.io.Writer; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.errors.ConfigInvalidException; @RequiresCapability(ImportCapability.ID) public class ResumeProjectImport implements RestModifyView<ImportProjectResource, Input> { @@ -97,24 +95,24 @@ @Override public ResumeImportStatistic apply(ImportProjectResource rsrc, Input input) - throws RestApiException, IOException, OrmException, ValidationException, - GitAPIException, NoSuchChangeException, NoSuchAccountException, - UpdateException, ConfigInvalidException, PermissionBackendException { + throws RestApiException, IOException, OrmException, ValidationException, GitAPIException, + NoSuchChangeException, NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { if (copy) { input.validateResumeCopy(); } else { input.validateResumeImport(); } - return importProjectFactory.create(rsrc.getName()) + return importProjectFactory + .create(rsrc.getName()) .setCopy(copy) .setErr(err) - .resume(input.user, input.pass, input.force, - rsrc.getImportStatus()); + .resume(input.user, input.pass, input.force, rsrc.getImportStatus()); } - public static class OnProjects implements - RestModifyView<ProjectResource, Input>, UiAction<ProjectResource> { + public static class OnProjects + implements RestModifyView<ProjectResource, Input>, UiAction<ProjectResource> { private final ProjectsCollection projectsCollection; private final ResumeProjectImport resumeProjectImport; private final Provider<CurrentUser> currentUserProvider; @@ -137,12 +135,11 @@ @Override public ResumeImportStatistic apply(ProjectResource rsrc, Input input) - throws RestApiException, IOException, OrmException, ValidationException, - GitAPIException, NoSuchChangeException, NoSuchAccountException, - UpdateException, ConfigInvalidException, PermissionBackendException { + throws RestApiException, IOException, OrmException, ValidationException, GitAPIException, + NoSuchChangeException, NoSuchAccountException, UpdateException, ConfigInvalidException, + PermissionBackendException, PatchListNotAvailableException { ImportProjectResource projectResource = - projectsCollection.parse(new ConfigResource(), - IdString.fromDecoded(rsrc.getName())); + projectsCollection.parse(new ConfigResource(), IdString.fromDecoded(rsrc.getName())); return resumeProjectImport.apply(projectResource, input); } @@ -155,17 +152,17 @@ } private boolean canResumeImport(ProjectResource rsrc) { - return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) || - (permissionBackend.user(currentUserProvider).testOrFalse( - new PluginPermission(pluginName, ImportCapability.ID)) && - rsrc.getControl().isOwner()); + return permissionBackend.user(currentUserProvider).testOrFalse(ADMINISTRATE_SERVER) + || (permissionBackend + .user(currentUserProvider) + .testOrFalse(new PluginPermission(pluginName, ImportCapability.ID)) + && rsrc.getControl().isOwner()); } private boolean isImported(ProjectResource rsrc) { try { ImportProjectResource projectResource = - projectsCollection.parse(new ConfigResource(), - IdString.fromDecoded(rsrc.getName())); + projectsCollection.parse(new ConfigResource(), IdString.fromDecoded(rsrc.getName())); ImportProjectInfo info = projectResource.getInfo(); if (info.from == null) { // no import, but a copy within the same system
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/AccountInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/AccountInfo.java index 18b44fa..7beb7aa 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/AccountInfo.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/AccountInfo.java
@@ -18,10 +18,12 @@ public class AccountInfo extends JavaScriptObject { public final native int _account_id() /*-{ return this._account_id || 0; }-*/; + public final native String name() /*-{ return this.name; }-*/; + public final native String username() /*-{ return this.username; }-*/; + public final native String email() /*-{ return this.email; }-*/; - protected AccountInfo() { - } + protected AccountInfo() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/CompleteImportDialog.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/CompleteImportDialog.java index e0339fa..a67964d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/CompleteImportDialog.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/CompleteImportDialog.java
@@ -33,7 +33,7 @@ private final Button completeButton; public CompleteImportDialog(final String project, final boolean copy) { - super(/* auto hide */false, /* modal */true); + super(/* auto hide */ false, /* modal */ true); setGlassEnabled(true); setText("Complete Project " + (copy ? "Copy" : "Import")); @@ -41,40 +41,43 @@ completeButton = new Button(); completeButton.setText("Complete"); - completeButton.addClickHandler(event -> { - hide(); + completeButton.addClickHandler( + event -> { + hide(); - new RestApi("config").id("server") - .view(Plugin.get().getName(), "projects").id(project) - .delete(new AsyncCallback<NoContent>() { - @Override - public void onSuccess(NoContent result) { - Plugin.get().go("/x/" + Plugin.get().getName() + "/list"); + new RestApi("config") + .id("server") + .view(Plugin.get().getName(), "projects") + .id(project) + .delete( + new AsyncCallback<NoContent>() { + @Override + public void onSuccess(NoContent result) { + Plugin.get().go("/x/" + Plugin.get().getName() + "/list"); - final DialogBox successDialog = new DialogBox(); - successDialog.setText("Project " - + (copy ? "Copy" : "Import") + " Completed"); - successDialog.setAnimationEnabled(true); + final DialogBox successDialog = new DialogBox(); + successDialog.setText("Project " + (copy ? "Copy" : "Import") + " Completed"); + successDialog.setAnimationEnabled(true); - Panel p = new VerticalPanel(); - p.setStyleName("importer-message-panel"); - p.add(new Label("The project " - + (copy ? "copy" : "import") + " was completed.")); - Button okButton = new Button("OK"); - okButton.addClickHandler(event -> successDialog.hide()); + Panel p = new VerticalPanel(); + p.setStyleName("importer-message-panel"); + p.add( + new Label( + "The project " + (copy ? "copy" : "import") + " was completed.")); + Button okButton = new Button("OK"); + okButton.addClickHandler(event -> successDialog.hide()); - p.add(okButton); - successDialog.add(p); + p.add(okButton); + successDialog.add(p); - successDialog.center(); - successDialog.show(); - } + successDialog.center(); + successDialog.show(); + } - @Override - public void onFailure(Throwable caught) { - } - }); - }); + @Override + public void onFailure(Throwable caught) {} + }); + }); buttons.add(completeButton); cancelButton = new Button(); @@ -84,8 +87,8 @@ buttons.add(cancelButton); FlowPanel center = new FlowPanel(); - Label msg = new Label("Complete " + (copy ? "copy" : "import") - + " of project '" + project + "'"); + Label msg = + new Label("Complete " + (copy ? "copy" : "import") + " of project '" + project + "'"); msg.addStyleName("importer-complete-message"); center.add(msg);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportActionPanel.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportActionPanel.java index 2dc3e57..7ee5431 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportActionPanel.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportActionPanel.java
@@ -22,11 +22,12 @@ ImportActionPanel(final String project, final boolean copy) { setStyleName("importer-action-panel"); - add(new Button("Resume...", - (ClickHandler) event -> (new ResumeImportDialog(project, copy)) - .center())); - add(new Button("Complete...", - (ClickHandler) event -> (new CompleteImportDialog(project, copy)) - .center())); + add( + new Button( + "Resume...", (ClickHandler) event -> (new ResumeImportDialog(project, copy)).center())); + add( + new Button( + "Complete...", + (ClickHandler) event -> (new CompleteImportDialog(project, copy)).center())); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupInput.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupInput.java index 4c12a81..6832e23 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupInput.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupInput.java
@@ -18,15 +18,18 @@ public class ImportGroupInput extends JavaScriptObject { final native void from(String f) /*-{ this.from = f; }-*/; + final native void user(String u) /*-{ this.user = u; }-*/; + final native void pass(String p) /*-{ this.pass = p; }-*/; + final native void importOwnerGroup(boolean i) /*-{ this.import_owner_group = i; }-*/; + final native void importIncludedGroups(boolean i) /*-{ this.import_included_groups = i; }-*/; static ImportGroupInput create() { return (ImportGroupInput) createObject(); } - protected ImportGroupInput() { - } + protected ImportGroupInput() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupScreen.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupScreen.java index a4e9cea..eef8892 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupScreen.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportGroupScreen.java
@@ -52,12 +52,16 @@ ImportGroupScreen() { setStyleName("importer-import-panel"); - fromTxt = addTextBox(this, "From*", "URL of the remote system from where the group should be imported"); + fromTxt = + addTextBox( + this, "From*", "URL of the remote system from where the group should be imported"); nameTxt = addTextBox(this, "Group Name*", "name of the group"); userTxt = addTextBox(this, "Remote User*", "user on remote system"); passTxt = addPasswordTextBox(this, "Password*", "password of remote user"); - importOwnerGroupCheckBox = addCheckBox(this, "import owner group", "also import missing owner groups"); - importIncludedGroupsCheckBox = addCheckBox(this, "import included groups", "also import missing included groups"); + importOwnerGroupCheckBox = + addCheckBox(this, "import owner group", "also import missing owner groups"); + importIncludedGroupsCheckBox = + addCheckBox(this, "import included groups", "also import missing included groups"); HorizontalPanel buttons = new HorizontalPanel(); add(buttons); @@ -82,35 +86,39 @@ in.importIncludedGroups(importIncludedGroupsCheckBox.getValue()); final String groupName = getValue(nameTxt); - new RestApi("config").id("server").view(Plugin.get().getName(), "groups") - .id(groupName).put(in, new AsyncCallback<JavaScriptObject>() { + new RestApi("config") + .id("server") + .view(Plugin.get().getName(), "groups") + .id(groupName) + .put( + in, + new AsyncCallback<JavaScriptObject>() { - @Override - public void onSuccess(JavaScriptObject result) { - clearForm(); - Plugin.get().go("/admin/groups/" + groupName); + @Override + public void onSuccess(JavaScriptObject result) { + clearForm(); + Plugin.get().go("/admin/groups/" + groupName); - final DialogBox successDialog = new DialogBox(); - successDialog.setText("Group Import"); - successDialog.setAnimationEnabled(true); + final DialogBox successDialog = new DialogBox(); + successDialog.setText("Group Import"); + successDialog.setAnimationEnabled(true); - Panel p = new VerticalPanel(); - p.setStyleName("importer-message-panel"); - p.add(new Label("The group was imported.")); - Button okButton = new Button("OK"); - okButton.addClickHandler(event -> successDialog.hide()); + Panel p = new VerticalPanel(); + p.setStyleName("importer-message-panel"); + p.add(new Label("The group was imported.")); + Button okButton = new Button("OK"); + okButton.addClickHandler(event -> successDialog.hide()); - p.add(okButton); - successDialog.add(p); + p.add(okButton); + successDialog.add(p); - successDialog.center(); - successDialog.show(); - } + successDialog.center(); + successDialog.show(); + } - @Override - public void onFailure(Throwable caught) { - } - }); + @Override + public void onFailure(Throwable caught) {} + }); } private void clearForm() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportInfo.java index 82978f0..812236b 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportInfo.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportInfo.java
@@ -18,9 +18,10 @@ public class ImportInfo extends JavaScriptObject { public final native String timestamp() /*-{ return this.timestamp; }-*/; + public final native AccountInfo user() /*-{ return this.user; }-*/; + public final native String remoteUser() /*-{ return this.remote_user; }-*/; - protected ImportInfo() { - } + protected ImportInfo() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInfo.java index e89f058..3d93c91 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInfo.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInfo.java
@@ -19,10 +19,12 @@ public class ImportProjectInfo extends JavaScriptObject { public final native String from() /*-{ return this.from; }-*/; + public final native String name() /*-{ return this.name; }-*/; + public final native String parent() /*-{ return this.parent; }-*/; + public final native JsArray<ImportInfo> imports() /*-{ return this.imports; }-*/; - protected ImportProjectInfo() { - } + protected ImportProjectInfo() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInput.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInput.java index a355e6a..6ae25cf 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInput.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInput.java
@@ -18,15 +18,18 @@ public class ImportProjectInput extends JavaScriptObject { final native void from(String f) /*-{ this.from = f; }-*/; + final native void name(String n) /*-{ this.name = n; }-*/; + final native void user(String u) /*-{ this.user = u; }-*/; + final native void pass(String p) /*-{ this.pass = p; }-*/; + final native void parent(String p) /*-{ this.parent = p; }-*/; static ImportProjectInput create() { return (ImportProjectInput) createObject(); } - protected ImportProjectInput() { - } + protected ImportProjectInput() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java index bd86574..3239acb 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java
@@ -25,7 +25,6 @@ import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter; import com.google.gwt.user.client.ui.InlineHyperlink; import com.google.gwt.user.client.ui.VerticalPanel; - import java.util.List; public class ImportProjectListScreen extends VerticalPanel { @@ -40,19 +39,21 @@ ImportProjectListScreen() { setStyleName("importer-imports-panel"); - new RestApi("config").id("server") + new RestApi("config") + .id("server") .view(Plugin.get().getPluginName(), "projects") - .get(new AsyncCallback<NativeMap<ImportProjectInfo>>() { - @Override - public void onSuccess(NativeMap<ImportProjectInfo> info) { - display(info); - } + .get( + new AsyncCallback<NativeMap<ImportProjectInfo>>() { + @Override + public void onSuccess(NativeMap<ImportProjectInfo> info) { + display(info); + } - @Override - public void onFailure(Throwable caught) { - // never invoked - } - }); + @Override + public void onFailure(Throwable caught) { + // never invoked + } + }); } private void display(NativeMap<ImportProjectInfo> map) { @@ -82,16 +83,17 @@ fmt.addStyleName(row, 0, "leftMostCell"); } - t.setWidget(row, 0, new InlineHyperlink( - project, "/x/" + Plugin.get().getName() + "/projects/" + project)); + t.setWidget( + row, + 0, + new InlineHyperlink(project, "/x/" + Plugin.get().getName() + "/projects/" + project)); t.setText(row, 1, info.from() != null ? "IMPORT" : "COPY"); if (info.from() != null) { String srcProjectUrl = projectUrl(info, project); t.setWidget(row, 2, new Anchor(srcProjectUrl, srcProjectUrl)); } else { - t.setWidget(row, 2, - new InlineHyperlink(project, "/admin/projects/" + project)); + t.setWidget(row, 2, new InlineHyperlink(project, "/admin/projects/" + project)); } List<ImportInfo> importList = Natives.asList(info.imports());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectScreen.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectScreen.java index 206f12d..6f3c785 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectScreen.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectScreen.java
@@ -49,14 +49,24 @@ ImportProjectScreen() { setStyleName("importer-import-panel"); - fromTxt = addTextBox(this, "From*", "URL of the remote system from where the project should be imported"); + fromTxt = + addTextBox( + this, "From*", "URL of the remote system from where the project should be imported"); srcNameTxt = addTextBox(this, "Project Name in Source*", "name of project in source system"); - targetNameTxt = addTextBox(this, "Target Project Name", "name of project in target system" - + " (if not specified it is assumed to be the same name as in the source system)"); + targetNameTxt = + addTextBox( + this, + "Target Project Name", + "name of project in target system" + + " (if not specified it is assumed to be the same name as in the source system)"); userTxt = addTextBox(this, "Remote User*", "user on remote system"); passTxt = addPasswordTextBox(this, "Password*", "password of remote user"); - parentTxt = addTextBox(this, "Parent", "name of parent project in target system" - + "(if not specified it is assumed to be the same parent as in the source system)"); + parentTxt = + addTextBox( + this, + "Parent", + "name of parent project in target system" + + "(if not specified it is assumed to be the same parent as in the source system)"); HorizontalPanel buttons = new HorizontalPanel(); add(buttons); @@ -73,8 +83,8 @@ } private void doImport() { - final String targetName = getValue(targetNameTxt).length() == 0 - ? getValue(srcNameTxt) : getValue(targetNameTxt); + final String targetName = + getValue(targetNameTxt).length() == 0 ? getValue(srcNameTxt) : getValue(targetNameTxt); ImportProjectInput in = ImportProjectInput.create(); in.from(getValue(fromTxt)); @@ -83,36 +93,40 @@ in.pass(getValue(passTxt)); in.parent(getValue(parentTxt)); - new RestApi("config").id("server").view(Plugin.get().getName(), "projects") - .id(targetName).put(in, new AsyncCallback<ImportStatisticInfo>() { + new RestApi("config") + .id("server") + .view(Plugin.get().getName(), "projects") + .id(targetName) + .put( + in, + new AsyncCallback<ImportStatisticInfo>() { - @Override - public void onSuccess(ImportStatisticInfo result) { - clearForm(); - Plugin.get().go("/admin/projects/" + targetName); + @Override + public void onSuccess(ImportStatisticInfo result) { + clearForm(); + Plugin.get().go("/admin/projects/" + targetName); - final DialogBox successDialog = new DialogBox(); - successDialog.setText("Project Import"); - successDialog.setAnimationEnabled(true); + final DialogBox successDialog = new DialogBox(); + successDialog.setText("Project Import"); + successDialog.setAnimationEnabled(true); - Panel p = new VerticalPanel(); - p.setStyleName("importer-message-panel"); - p.add(new Label("The project was imported.")); - p.add(new Label("Created Changes: " + result.numChangesCreated())); - Button okButton = new Button("OK"); - okButton.addClickHandler(event -> successDialog.hide()); + Panel p = new VerticalPanel(); + p.setStyleName("importer-message-panel"); + p.add(new Label("The project was imported.")); + p.add(new Label("Created Changes: " + result.numChangesCreated())); + Button okButton = new Button("OK"); + okButton.addClickHandler(event -> successDialog.hide()); - p.add(okButton); - successDialog.add(p); + p.add(okButton); + successDialog.add(p); - successDialog.center(); - successDialog.show(); - } + successDialog.center(); + successDialog.show(); + } - @Override - public void onFailure(Throwable caught) { - } - }); + @Override + public void onFailure(Throwable caught) {} + }); } private void clearForm() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportStatisticInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportStatisticInfo.java index 2d82432..dfd5daf 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportStatisticInfo.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportStatisticInfo.java
@@ -19,6 +19,5 @@ public class ImportStatisticInfo extends JavaScriptObject { public final native int numChangesCreated() /*-{ return this.num_changes_created; }-*/; - protected ImportStatisticInfo() { - } + protected ImportStatisticInfo() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/InputUtil.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/InputUtil.java index 1f9d55d..da7402d 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/InputUtil.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/InputUtil.java
@@ -53,21 +53,23 @@ private static TextBox createTextBox(boolean isPassword) { TextBox tb; if (isPassword) { - tb = new PasswordTextBox() { - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - handlePaste(this, event); - } - }; + tb = + new PasswordTextBox() { + @Override + public void onBrowserEvent(Event event) { + super.onBrowserEvent(event); + handlePaste(this, event); + } + }; } else { - tb = new TextBox() { - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - handlePaste(this, event); - } - }; + tb = + new TextBox() { + @Override + public void onBrowserEvent(Event event) { + super.onBrowserEvent(event); + handlePaste(this, event); + } + }; } tb.addKeyPressHandler(event -> event.stopPropagation()); tb.sinkEvents(Event.ONPASTE); @@ -77,11 +79,13 @@ private static void handlePaste(final TextBox tb, Event event) { if (event.getTypeInt() == Event.ONPASTE) { - Scheduler.get().scheduleDeferred(() -> { - if (getValue(tb).length() != 0) { - tb.setEnabled(true); - } - }); + Scheduler.get() + .scheduleDeferred( + () -> { + if (getValue(tb).length() != 0) { + tb.setEnabled(true); + } + }); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/OnEditEnabler.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/OnEditEnabler.java index d632652..986fc64 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/OnEditEnabler.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/OnEditEnabler.java
@@ -31,22 +31,23 @@ import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.TextBoxBase; import com.google.gwt.user.client.ui.ValueBoxBase; - import java.util.HashMap; import java.util.Map; - -/** Enables a FocusWidget (e.g. a Button) if an edit is detected from any - * registered input widget. +/** + * Enables a FocusWidget (e.g. a Button) if an edit is detected from any registered input widget. */ -public class OnEditEnabler implements KeyPressHandler, KeyDownHandler, - MouseUpHandler, ChangeHandler, ValueChangeHandler<Object> { +public class OnEditEnabler + implements KeyPressHandler, + KeyDownHandler, + MouseUpHandler, + ChangeHandler, + ValueChangeHandler<Object> { private final FocusWidget widget; private Map<TextBoxBase, String> strings = new HashMap<>(); private String originalValue; - // The first parameter to the contructors must be the FocusWidget to enable, // subsequent parameters are widgets to listenTo. @@ -70,7 +71,6 @@ widget = w; } - // Register input widgets to be listened to public void listenTo(final TextBoxBase tb) { @@ -101,7 +101,6 @@ cb.addValueChangeHandler((ValueChangeHandler) this); } - // Handlers @Override @@ -131,16 +130,18 @@ } private void on(final GwtEvent<?> e) { - if (widget.isEnabled() || - ! (e.getSource() instanceof FocusWidget) || - ! ((FocusWidget) e.getSource()).isEnabled() ) { + if (widget.isEnabled() + || !(e.getSource() instanceof FocusWidget) + || !((FocusWidget) e.getSource()).isEnabled()) { if (e.getSource() instanceof ValueBoxBase) { final TextBoxBase box = ((TextBoxBase) e.getSource()); - Scheduler.get().scheduleDeferred(() -> { - if (box.getValue().trim().equals(originalValue)) { - widget.setEnabled(false); - } - }); + Scheduler.get() + .scheduleDeferred( + () -> { + if (box.getValue().trim().equals(originalValue)) { + widget.setEnabled(false); + } + }); } return; } @@ -157,14 +158,16 @@ private void onTextBoxBase(final TextBoxBase tb) { // The text appears to not get updated until the handlers complete. - Scheduler.get().scheduleDeferred(() -> { - String orig = strings.get(tb); - if (orig == null) { - orig = ""; - } - if (! orig.equals(tb.getText().trim())) { - widget.setEnabled(true); - } - }); + Scheduler.get() + .scheduleDeferred( + () -> { + String orig = strings.get(tb); + if (orig == null) { + orig = ""; + } + if (!orig.equals(tb.getText().trim())) { + widget.setEnabled(true); + } + }); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ProjectImportsScreen.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ProjectImportsScreen.java index 8cbb2eb..879b09c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ProjectImportsScreen.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ProjectImportsScreen.java
@@ -29,7 +29,6 @@ import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; - import java.util.Collections; import java.util.List; @@ -45,18 +44,22 @@ ProjectImportsScreen(final String project) { setStyleName("importer-import-panel"); - new RestApi("config").id("server").view(Plugin.get().getPluginName(), "projects") - .id(project).get(new AsyncCallback<ImportProjectInfo>() { - @Override - public void onSuccess(ImportProjectInfo importProjectInfo) { - display(project, importProjectInfo); - } + new RestApi("config") + .id("server") + .view(Plugin.get().getPluginName(), "projects") + .id(project) + .get( + new AsyncCallback<ImportProjectInfo>() { + @Override + public void onSuccess(ImportProjectInfo importProjectInfo) { + display(project, importProjectInfo); + } - @Override - public void onFailure(Throwable caught) { - // never invoked - } - }); + @Override + public void onFailure(Throwable caught) { + // never invoked + } + }); } private void display(final String project, ImportProjectInfo info) { @@ -69,11 +72,9 @@ String srcProjectUrl = projectUrl(info, project); t.addRow("From", new Anchor(srcProjectUrl, srcProjectUrl)); } else { - t.addRow("From", - new InlineHyperlink(project, "/admin/projects/" + project)); + t.addRow("From", new InlineHyperlink(project, "/admin/projects/" + project)); } - t.addRow("Parent", info.parent()); t.addRow("Actions", new ImportActionPanel(project, info.from() == null)); add(t);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeCopyProjectInput.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeCopyProjectInput.java index fa101f0..cc1f880 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeCopyProjectInput.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeCopyProjectInput.java
@@ -23,6 +23,5 @@ return (ResumeCopyProjectInput) createObject(); } - protected ResumeCopyProjectInput() { - } + protected ResumeCopyProjectInput() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportDialog.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportDialog.java index b56f46d..a8264c1 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportDialog.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportDialog.java
@@ -42,7 +42,7 @@ private CheckBox forceCheckBox; public ResumeImportDialog(final String project, final boolean copy) { - super(/* auto hide */false, /* modal */true); + super(/* auto hide */ false, /* modal */ true); setGlassEnabled(true); setText("Resume Project " + (copy ? "Copy" : "Import")); @@ -50,52 +50,57 @@ resumeButton = new Button(); resumeButton.setText("Resume"); - resumeButton.addClickHandler(event -> { - hide(); + resumeButton.addClickHandler( + event -> { + hide(); - RestApi restApi; - ResumeImportProjectInput in = ResumeImportProjectInput.create(); - in.force(forceCheckBox.getValue()); - if (copy) { - restApi = new RestApi("projects").id(project) - .view(Plugin.get().getName(), "copy.resume"); - } else { - restApi = new RestApi("config").id("server") - .view(Plugin.get().getName(), "projects").id(project) - .view("resume"); - in.user(getValue(userTxt)); - in.pass(getValue(passTxt)); - } + RestApi restApi; + ResumeImportProjectInput in = ResumeImportProjectInput.create(); + in.force(forceCheckBox.getValue()); + if (copy) { + restApi = + new RestApi("projects").id(project).view(Plugin.get().getName(), "copy.resume"); + } else { + restApi = + new RestApi("config") + .id("server") + .view(Plugin.get().getName(), "projects") + .id(project) + .view("resume"); + in.user(getValue(userTxt)); + in.pass(getValue(passTxt)); + } - restApi.put(in, new AsyncCallback<ResumeImportStatisticInfo>() { - @Override - public void onSuccess(ResumeImportStatisticInfo result) { - Plugin.get().go("/x/" + Plugin.get().getName() + "/list"); + restApi.put( + in, + new AsyncCallback<ResumeImportStatisticInfo>() { + @Override + public void onSuccess(ResumeImportStatisticInfo result) { + Plugin.get().go("/x/" + Plugin.get().getName() + "/list"); - final DialogBox successDialog = new DialogBox(); - successDialog.setText("Resume " + (copy ? "Copy" : "Import") + " Import"); - successDialog.setAnimationEnabled(true); + final DialogBox successDialog = new DialogBox(); + successDialog.setText("Resume " + (copy ? "Copy" : "Import") + " Import"); + successDialog.setAnimationEnabled(true); - Panel p = new VerticalPanel(); - p.setStyleName("importer-message-panel"); - p.add(new Label("The project " + (copy ? "copy" : "import") + " was resumed.")); - p.add(new Label("Created Changes: " + result.numChangesCreated())); - p.add(new Label("Updated Changes: " + result.numChangesUpdated())); - Button okButton = new Button("OK"); - okButton.addClickHandler(event -> successDialog.hide()); + Panel p = new VerticalPanel(); + p.setStyleName("importer-message-panel"); + p.add(new Label("The project " + (copy ? "copy" : "import") + " was resumed.")); + p.add(new Label("Created Changes: " + result.numChangesCreated())); + p.add(new Label("Updated Changes: " + result.numChangesUpdated())); + Button okButton = new Button("OK"); + okButton.addClickHandler(event -> successDialog.hide()); - p.add(okButton); - successDialog.add(p); + p.add(okButton); + successDialog.add(p); - successDialog.center(); - successDialog.show(); - } + successDialog.center(); + successDialog.show(); + } - @Override - public void onFailure(Throwable caught) { - } - }); - }); + @Override + public void onFailure(Throwable caught) {} + }); + }); buttons.add(resumeButton); cancelButton = new Button(); @@ -105,8 +110,7 @@ buttons.add(cancelButton); FlowPanel center = new FlowPanel(); - Label msg = new Label("Resume " + (copy ? "copy" : "import") - + " of project '" + project + "'"); + Label msg = new Label("Resume " + (copy ? "copy" : "import") + " of project '" + project + "'"); msg.addStyleName("importer-resume-message"); center.add(msg);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportProjectInput.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportProjectInput.java index 47bdaf7..cb8d20f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportProjectInput.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportProjectInput.java
@@ -16,12 +16,12 @@ public class ResumeImportProjectInput extends ResumeCopyProjectInput { final native void user(String u) /*-{ this.user = u; }-*/; + final native void pass(String p) /*-{ this.pass = p; }-*/; static ResumeImportProjectInput create() { return (ResumeImportProjectInput) createObject(); } - protected ResumeImportProjectInput() { - } + protected ResumeImportProjectInput() {} }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportStatisticInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportStatisticInfo.java index 73d99f1..354e682 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportStatisticInfo.java +++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ResumeImportStatisticInfo.java
@@ -14,10 +14,8 @@ package com.googlesource.gerrit.plugins.importer.client; - public class ResumeImportStatisticInfo extends ImportStatisticInfo { public final native int numChangesUpdated() /*-{ return this.num_changes_updated; }-*/; - protected ResumeImportStatisticInfo() { - } + protected ResumeImportStatisticInfo() {} }
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md index b914b97..40814f0 100644 --- a/src/main/resources/Documentation/about.md +++ b/src/main/resources/Documentation/about.md
@@ -1,7 +1,7 @@ The @PLUGIN@ plugin allows to import projects and groups from a remote Gerrit server into the Gerrit server where the plugin is installed. -The imports are done online while both, source and target Gerrit +The imports are done online while both source and target Gerrit server, are running. The user that does the import must be a member of a group that is @@ -40,8 +40,7 @@ On project import the configured max object size on the target Gerrit server is ignored. -Draft changes, draft patch sets, change edits and draft comments are -*not* imported. +Change edits and draft comments are *not* imported. #### Process @@ -92,9 +91,9 @@ Account] or the link:access-control.html#capability_administrateServer[ Administrate Server] capability assigned on the source system. -If for any reason an user is no longer existent in the LDAP instance but it +If for any reason a user no longer exists in the LDAP instance but it is listed as a change owner, reviewer or as part of a group, a local user -account is created with the same username. Giving that such user is not longer +account is created with the same username. Given that such a user is no longer active in the system, their account status is set to inactive. Gerrit internal users (e.g. service users) should be created in the target
diff --git a/tools/bzl/classpath.bzl b/tools/bzl/classpath.bzl index dfcbe9c..d5764f7 100644 --- a/tools/bzl/classpath.bzl +++ b/tools/bzl/classpath.bzl
@@ -1,2 +1,4 @@ -load("@com_googlesource_gerrit_bazlets//tools:classpath.bzl", - "classpath_collector") +load( + "@com_googlesource_gerrit_bazlets//tools:classpath.bzl", + "classpath_collector", +)
diff --git a/tools/bzl/plugin.bzl b/tools/bzl/plugin.bzl index 74d4ce1..a280a0f 100644 --- a/tools/bzl/plugin.bzl +++ b/tools/bzl/plugin.bzl
@@ -1,6 +1,6 @@ load( "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", - "gerrit_plugin", - "PLUGIN_DEPS", "GWT_PLUGIN_DEPS", + "PLUGIN_DEPS", + "gerrit_plugin", )
diff --git a/tools/eclipse/BUILD b/tools/eclipse/BUILD index 9b749e1..abc0526 100644 --- a/tools/eclipse/BUILD +++ b/tools/eclipse/BUILD
@@ -1,13 +1,15 @@ load( "//tools/bzl:plugin.bzl", - "PLUGIN_DEPS", "GWT_PLUGIN_DEPS", + "PLUGIN_DEPS", ) load("//tools/bzl:classpath.bzl", "classpath_collector") classpath_collector( name = "main_classpath_collect", deps = PLUGIN_DEPS + GWT_PLUGIN_DEPS + [ + "//external:gwt-dev", + "//external:gwt-user", "//:importer__plugin", ], )