CONTRIBUTING.adoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. _Have something you'd like to contribute to the framework? We welcome pull requests, but ask that you carefully read this document first to understand how best to submit them; what kind of changes are likely to be accepted; and what to expect from the Spring Security team when evaluating your submission._
  2. _Please refer back to this document as a checklist before issuing any pull request; this will save time for everyone!_
  3. = Code of Conduct
  4. Please see our https://github.com/spring-projects/.github/blob/main/CODE_OF_CONDUCT.md[code of conduct].
  5. = Similar but different
  6. Each Spring module is slightly different from one another in terms of team size, number of issues, etc. Therefore, each project is managed slightly different. You will notice that this document is very similar to the https://github.com/spring-projects/spring-framework/wiki/Contributor-guidelines[Spring Framework Contributor guidelines]. However, there are some subtle differences between the two documents, so please be sure to read this document thoroughly.
  7. = Importing into IDE
  8. The following provides information on setting up a development environment that can run the sample in https://www.springsource.org/sts[Spring Tool Suite 3.6.0+]. Other IDE's should work using Gradle's IDE support, but have not been tested.
  9. * IDE Setup
  10. ** Install Spring Tool Suite 3.6.0+
  11. ** You will need the following plugins installed (can be found on the Extensions Page)
  12. *** Gradle Eclipse
  13. *** Groovy Eclipse
  14. * Importing the project into Spring Tool Suite
  15. ** File -> Import… -> Gradle Project
  16. As of new versions of Spring Tool Suite, you might need to install Groovy Eclipse pointing directly to the updated plugin location. To install Groovy Eclipse on Spring Tool Suite based on Eclipse Oxigen you must do the following steps:
  17. Help -> Install New Software… -> Add the following URL into _Work with_ field:
  18. https://dist.springsource.org/snapshot/GRECLIPSE/e4.7/[https://dist.springsource.org/snapshot/GRECLIPSE/e4.7/]
  19. = Understand the basics
  20. Not sure what a pull request is, or how to submit one? Take a look at GitHub's excellent https://help.github.com/articles/using-pull-requests[help documentation first].
  21. = Search GitHub issues; create an issue if necessary
  22. Is there already an issue that addresses your concern? Do a bit of searching in our https://github.com/spring-projects/spring-security/issues[GitHub issues] to see if you can find something similar. If not, please create a new issue before submitting a pull request unless the change is not a user facing issue.
  23. = Discuss non-trivial contribution ideas with committers
  24. If you're considering anything more than correcting a typo or fixing a minor bug, please discuss it on the https://gitter.im/spring-projects/spring-security[Spring Security Gitter] before submitting a pull request. We're happy to provide guidance but please spend an hour or two researching the subject on your own including searching the forums for prior discussions.
  25. = Sign the Contributor License Agreement
  26. If you have not previously done so, please fill out and submit the https://cla.pivotal.io/sign/spring[Contributor License Agreement].
  27. = Create your branch from oldest maintenance branch
  28. Create your topic branch to be submitted as a pull request from the oldest impacted and supported maintenance branch.
  29. You can find the supported versions by looking at the https://github.com/spring-projects/spring-security/milestones[milestones page].
  30. Switch to a branch named `<major>.<minor>.x` from the smallest milestone in the format of `<major>.<minor>.<patch>(-<prerelease>)`.
  31. The spring team will ensure the code gets merged forward into additional branches.
  32. = Use short branch names
  33. Branches used when submitting pull requests should preferably be named according to GitHub issues, e.g. `gh-1234` or `gh-1234-fix-npe`. Otherwise, use succinct, lower-case, dash (`-`) delimited names, such as `fix-warnings` or `fix-typo`. This is important, because branch names show up in the merge commits that result from accepting pull requests, and should be as expressive and concise as possible.
  34. = Keep commits focused
  35. Remember each ticket should be focused on a single item of interest since the tickets are used to produce the changelog. Since each commit should be tied to a single GitHub issue, ensure that your commits are focused. For example, do not include an update to a transitive library in your commit unless the GitHub is to update the library. Reviewing your commits is essential before sending a pull request.
  36. = Mind the whitespace
  37. Please carefully follow the whitespace and formatting conventions already present in the framework.
  38. . Tabs, not spaces
  39. . Unix (LF), not dos (CRLF) line endings
  40. . Eliminate all trailing whitespace
  41. . Aim to wrap code at 120 characters, but favor readability over wrapping
  42. . Preserve existing formatting; i.e. do not reformat code for its own sake
  43. . Search the codebase using `git grep` and other tools to discover common naming conventions, etc.
  44. . UTF-8 encoding for Java sources and XML files
  45. Whitespace management tips
  46. . You can use the https://marketplace.eclipse.org/content/anyedit-tools[AnyEdit Eclipse plugin] to ensure spaces are used and to clean up trailing whitespaces.
  47. . Use Git's `pre-commit.sample` hook to prevent invalid whitespace from being pushed out. You can enable it by moving `.git/hooks/pre-commit.sample` to `.git/hooks/pre-commit` and ensuring it is executable. For more information on hooks refer to https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks[https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks].
  48. = Add Apache license header to all new classes
  49. ----
  50. /*
  51. * Copyright 2002-2020 the original author or authors.
  52. *
  53. * Licensed under the Apache License, Version 2.0 (the "License");
  54. * you may not use this file except in compliance with the License.
  55. * You may obtain a copy of the License at
  56. *
  57. * https://www.apache.org/licenses/LICENSE-2.0
  58. *
  59. * Unless required by applicable law or agreed to in writing, software
  60. * distributed under the License is distributed on an "AS IS" BASIS,
  61. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  62. * See the License for the specific language governing permissions and
  63. * limitations under the License.
  64. */
  65. package ...;
  66. ----
  67. = Update Apache license header to modified files as necessary
  68. Always check the date range in the license header. For example, if you've modified a file in 2020 whose header still reads
  69. ----
  70. * Copyright 2002-2012 the original author or authors.
  71. ----
  72. then be sure to update it to the current year appropriately (e.g. 2020)
  73. ----
  74. * Copyright 2002-2020 the original author or authors.
  75. ----
  76. = Use @since tags for newly-added public API types and methods
  77. Example:
  78. ----
  79. /**
  80. * …
  81. *
  82. * @author First Last
  83. * @since 5.4
  84. * @see …
  85. */
  86. ----
  87. = Submit JUnit test cases for all behavior changes
  88. Search the codebase to find related unit tests and add additional `@Test` methods within.
  89. . Any new tests should end in the name `Tests` (note this is plural). For example, a valid name would be `FilterChainProxyTests`. An invalid name would be `FilterChainProxyTest`.
  90. . New test methods should not start with test. This is an old JUnit3 convention and is not necessary since the method is annotated with `@Test`.
  91. = Update spring-security-x.y.rnc for schema changes
  92. Update the https://www.relaxng.org[RELAX NG] schema `spring-security-x.y.rnc` instead of `spring-security-x.y.xsd` if you contribute changes to supported XML configuration. The XML schema file can be generated the following Gradle task:
  93. ----
  94. ./gradlew :spring-security-config:rncToXsd
  95. ----
  96. Changes to the XML schema will be overwritten by the Gradle build task.
  97. = Squash commits
  98. Use `git rebase --interactive`, `git add --patch` and other tools to "squash" multiple commits into atomic changes. In addition to the man pages for `git`, there are https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History[many resources online] to help you understand how these tools work.
  99. = Use real name in git commits
  100. Please configure Git to use your real first and last name for any commits you intend to submit as pull requests. Make sure the name is properly capitalized as submitted to the https://cla.pivotal.io[Pivotal Contributor License Agreement]:
  101. ----
  102. First Last <user@mail.com>
  103. ----
  104. This helps ensure traceability against the CLA, and also goes a long way to ensuring useful output from tools like Git shortlog and others.
  105. You can configure this globally:
  106. ----
  107. git config --global user.name "First Last"
  108. git config --global user.email user@example.com
  109. ----
  110. or locally for the current repository by omitting the `--global` flag:
  111. ----
  112. git config user.name "First Last"
  113. git config user.email user@example.com
  114. ----
  115. = Format commit messages
  116. . Keep the subject line to 50 characters or less if possible
  117. . Do not end the subject line with a period
  118. . In the body of the commit message, explain how things worked before this commit, what has changed, and how things work now
  119. . Include `Closes gh-<issue-number>` at the end if this fixes a GitHub issue
  120. . Avoid markdown, including back-ticks identifying code
  121. Example:
  122. ----
  123. Short (50 chars or less) summary of changes
  124. More detailed explanatory text, if necessary. Wrap it to about 72
  125. characters or so. In some contexts, the first line is treated as the
  126. subject of an email and the rest of the text as the body. The blank
  127. line separating the summary from the body is critical (unless you omit
  128. the body entirely); tools like rebase can get confused if you run the
  129. two together.
  130. Further paragraphs come after blank lines.
  131. - Bullet points are okay, too
  132. - Typically a hyphen or asterisk is used for the bullet, preceded by a
  133. single space, with blank lines in between, but conventions vary here
  134. Closes gh-123
  135. ----
  136. = Run all tests prior to submission
  137. ----
  138. ./gradlew clean build integrationTest
  139. ----
  140. = Submit your pull request
  141. *Subject line:*
  142. Follow the same conventions for pull request subject lines as mentioned above for commit message subject lines.
  143. *In the body:*
  144. . Explain your use case. What led you to submit this change? Why were existing mechanisms in the framework insufficient? Make a case that this is a general-purpose problem and that yours is a general-purpose solution, etc
  145. . Add any additional information and ask questions; start a conversation, or continue one from GitHub Issues
  146. . Mention any GitHub Issues
  147. . Also mention that you have submitted the CLA as described above
  148. Note that for pull requests containing a single commit, GitHub will default the subject line and body of the pull request to match the subject line and body of the commit message. This is fine, but please also include the items above in the body of the request.
  149. = Mention your pull request on the associated GitHub issue
  150. Add a comment to the associated GitHub issue(s) linking to your new pull request.
  151. = Expect discussion and rework
  152. The Spring team takes a very conservative approach to accepting contributions to the framework. This is to keep code quality and stability as high as possible, and to keep complexity at a minimum. Your changes, if accepted, may be heavily modified prior to merging. You will retain "Author:" attribution for your Git commits granted that the bulk of your changes remain intact. You may be asked to rework the submission for style (as explained above) and/or substance. Again, we strongly recommend discussing any serious submissions with the Spring Framework team prior to engaging in serious development work.
  153. Note that you can always force push (`git push -f`) reworked / rebased commits against the branch used to submit your pull request. i.e. you do not need to issue a new pull request when asked to make changes.