├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── github-core ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.ui.prefs ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── github │ │ └── maven │ │ └── plugins │ │ └── core │ │ ├── GitHubProjectMojo.java │ │ ├── PathUtils.java │ │ ├── RateLimitedGitHubClient.java │ │ ├── RepositoryUtils.java │ │ ├── StringUtils.java │ │ └── egit │ │ └── GitHubClientEgit.java │ └── test │ ├── java │ └── com │ │ └── github │ │ └── maven │ │ └── plugins │ │ └── core │ │ ├── ClientCredentialsTest.java │ │ ├── CustomHostnameTest.java │ │ ├── MatchNonProxyTest.java │ │ ├── PathUtilsTest.java │ │ ├── RepositoryUtilsTest.java │ │ └── StringUtilsTest.java │ └── resources │ └── settings │ └── proxy │ ├── nonproxy-github.xml │ ├── nonproxy-github_and_api.xml │ ├── nonproxy-github_wildcard.xml │ ├── nonproxy-intra_github-no_same_id.xml │ └── nonproxy-intra_github.xml ├── github-site-plugin ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.jdt.ui.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── github │ │ └── maven │ │ └── plugins │ │ └── site │ │ └── SiteMojo.java │ └── site │ ├── markdown │ ├── authentication.md.vm │ ├── index.md.vm │ ├── locations.md.vm │ ├── phase.md.vm │ ├── project.md.vm │ └── quickstart.md.vm │ └── site.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | target 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | notifications: 4 | email: 5 | on_success: never 6 | on_failure: change 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 GitHub Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Maven Plugins [![Build Status](https://travis-ci.org/github/maven-plugins.svg)](https://travis-ci.org/github/maven-plugins) 2 | 3 | Collection of [Maven](http://maven.apache.org/) plugins that integrate with GitHub. 4 | These plugins are built on top of [API v3](http://developer.github.com/) through the 5 | [GitHub Java library](https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core). 6 | 7 | Released builds are available from [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Ccom.github.github). 8 | 9 | ## Core Configuration 10 | 11 | The plugins support several configuration options that can either be expressed 12 | in your project's POM file or in your `settings.xml` file. Where you put the 13 | plugin settings depends on whether you want a specific setting to be configured 14 | globally or on a per-project basis. 15 | 16 | All GitHub Maven plugins support the following core configuration elements. 17 | 18 | The notation below shows the plugin configuration property name followed 19 | by the settings configuration property in parentheses. 20 | 21 | * `host` (`github.global.host`) 22 | * Domain of GitHub API calls (defaults to `api.github.com`) 23 | * `oauth2Token` (`github.global.oauth2Token`) 24 | * OAuth2 access token for API authentication 25 | * [More about GitHub OAuth support](http://developer.github.com/v3/oauth/) 26 | * `userName` (`github.global.userName`) 27 | * GitHub user name used for API authentication 28 | * `password` (`github.global.password`) 29 | * GitHub password used for API authentication 30 | * `server` (`github.global.server`) 31 | * Id of the `server` element from the `settings.xml`. To use standard authentication 32 | set the `username` and `password` elements in the `servers` section of your 33 | `settings.xml` file along with an `id`. Configure an OAuth2 token by leaving the 34 | `username` element blank/missing and just specify the token in the `password` element. 35 | * This option should be used **instead of** configuring any of `userName`, `password` 36 | or `oauth2Token` in the plugin `configuration` element or as a properties. 37 | * `repositoryName` 38 | * Name of repository 39 | * `repositoryOwner` 40 | * Owner of repository 41 | 42 | *Note:* `repositoryOwner` property and `repositoryName` are optional and will be 43 | inferred from the following properties if not specified 44 | 45 | * `project.scm.url` 46 | * `project.scm.connection` 47 | * `project.scm.developerConnection` 48 | * `project.url` 49 | 50 | ### Authentication Example 51 | 52 | #### settings.xml 53 | 54 | ```xml 55 | 56 | 57 | github 58 | GitHubLogin 59 | GitHubPassw0rd 60 | 61 | 62 | ``` 63 | or 64 | ```xml 65 | 66 | 67 | github 68 | OAUTH2TOKEN 69 | 70 | 71 | ``` 72 | 73 | #### pom.xml 74 | 75 | ```xml 76 | 77 | github 78 | 79 | ``` 80 | 81 | ## [Site Plugin](http://github.github.com/maven-plugins/site-plugin) 82 | Maven plugin that commits files generated and updates a specific branch 83 | reference in a GitHub repository. This plugin can be used to deploy a created 84 | Maven site to a `gh-pages` branch so that it can be served statically as a 85 | GitHub Project Page. The plugin has a `site` goal and is configured with a goal 86 | prefix of `ghSite`. 87 | 88 | ### Configuration 89 | 90 | * `branch` 91 | * Branch ref that will be updated to commit made 92 | * Default: `refs/heads/gh-pages` 93 | * `message` 94 | * Message used for commit 95 | * `outputDirectory` 96 | * Directory that includes and excludes will be relative to 97 | * Defaults to `siteOutputDirectory` or `project.reporting.outputDirectory` 98 | * `includes` 99 | * Sub-elements will be treated as patterns to include from the 100 | `outputDirectory` 101 | * `excludes` 102 | * Sub-elements will be treated as patterns to exclude from the 103 | `outputDirectory` 104 | * `path` 105 | * Path relative to the root of the repository that all blobs should be 106 | relative to 107 | * `force` (`github.site.force`) 108 | * `true` | `false` (default: `false`) 109 | * Whether to force a ref update, default is fast-forwards only 110 | * `merge` (`github.site.merge`) 111 | * `true` | `false` (default: `false`) 112 | * Whether to merge with the current tree or completely replace the tree that 113 | the commit points to 114 | * `dryRun` (`github.site.dryRun`) 115 | * `true` | `false` (default: `false`) 116 | * Log what blobs, tree, and commits *would* be created without actually 117 | creating them 118 | * `noJekyll` (`github.site.noJekyll`) 119 | * `true` | `false` (default: `false`) 120 | * Whether to always create a `.nojekyll` file at the root of the site if one 121 | doesn't already exist. This setting should be enabled if your site contains 122 | any folders that begin with an underscore. 123 | 124 | ### Example 125 | ```xml 126 | 127 | 128 | 129 | com.github.github 130 | site-maven-plugin 131 | 0.12 132 | 133 | Creating site for ${project.version} 134 | 135 | 136 | 137 | 138 | site 139 | 140 | site 141 | 142 | 143 | 144 | 145 | 146 | ``` 147 | 148 | To commit a created site run the following command: 149 | 150 | `$ mvn site` 151 | 152 | # License 153 | * [MIT License](http://www.opensource.org/licenses/mit-license.php) 154 | -------------------------------------------------------------------------------- /github-core/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /github-core/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | github-maven-core 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /github-core/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 3 | sp_cleanup.add_default_serial_version_id=true 4 | sp_cleanup.add_generated_serial_version_id=false 5 | sp_cleanup.add_missing_annotations=false 6 | sp_cleanup.add_missing_deprecated_annotations=true 7 | sp_cleanup.add_missing_methods=false 8 | sp_cleanup.add_missing_nls_tags=false 9 | sp_cleanup.add_missing_override_annotations=true 10 | sp_cleanup.add_missing_override_annotations_interface_methods=false 11 | sp_cleanup.add_serial_version_id=false 12 | sp_cleanup.always_use_blocks=true 13 | sp_cleanup.always_use_parentheses_in_expressions=false 14 | sp_cleanup.always_use_this_for_non_static_field_access=false 15 | sp_cleanup.always_use_this_for_non_static_method_access=false 16 | sp_cleanup.convert_to_enhanced_for_loop=false 17 | sp_cleanup.correct_indentation=false 18 | sp_cleanup.format_source_code=false 19 | sp_cleanup.format_source_code_changes_only=false 20 | sp_cleanup.make_local_variable_final=false 21 | sp_cleanup.make_parameters_final=false 22 | sp_cleanup.make_private_fields_final=true 23 | sp_cleanup.make_type_abstract_if_missing_method=false 24 | sp_cleanup.make_variable_declarations_final=false 25 | sp_cleanup.never_use_blocks=false 26 | sp_cleanup.never_use_parentheses_in_expressions=true 27 | sp_cleanup.on_save_use_additional_actions=true 28 | sp_cleanup.organize_imports=false 29 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 30 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 31 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 32 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 33 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 34 | sp_cleanup.remove_private_constructors=true 35 | sp_cleanup.remove_trailing_whitespaces=true 36 | sp_cleanup.remove_trailing_whitespaces_all=true 37 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 38 | sp_cleanup.remove_unnecessary_casts=false 39 | sp_cleanup.remove_unnecessary_nls_tags=false 40 | sp_cleanup.remove_unused_imports=false 41 | sp_cleanup.remove_unused_local_variables=false 42 | sp_cleanup.remove_unused_private_fields=true 43 | sp_cleanup.remove_unused_private_members=false 44 | sp_cleanup.remove_unused_private_methods=true 45 | sp_cleanup.remove_unused_private_types=true 46 | sp_cleanup.sort_members=false 47 | sp_cleanup.sort_members_all=false 48 | sp_cleanup.use_blocks=false 49 | sp_cleanup.use_blocks_only_for_return_and_throw=false 50 | sp_cleanup.use_parentheses_in_expressions=false 51 | sp_cleanup.use_this_for_non_static_field_access=false 52 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 53 | sp_cleanup.use_this_for_non_static_method_access=false 54 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 55 | -------------------------------------------------------------------------------- /github-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.github.github 6 | github-maven-plugins-parent 7 | 0.13-SNAPSHOT 8 | 9 | 10 | github-maven-core 11 | GitHub Core Maven Library 12 | Core library for GitHub Maven plugins 13 | 14 | 15 | -------------------------------------------------------------------------------- /github-core/src/main/java/com/github/maven/plugins/core/GitHubProjectMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import com.github.maven.plugins.core.egit.GitHubClientEgit; 25 | import org.apache.maven.execution.MavenSession; 26 | import org.apache.maven.plugin.AbstractMojo; 27 | import org.apache.maven.plugin.MojoExecutionException; 28 | import org.apache.maven.plugin.logging.Log; 29 | import org.apache.maven.project.MavenProject; 30 | import org.apache.maven.settings.Proxy; 31 | import org.apache.maven.settings.Server; 32 | import org.apache.maven.settings.Settings; 33 | import org.eclipse.egit.github.core.RepositoryId; 34 | import org.eclipse.egit.github.core.client.GitHubClient; 35 | import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; 36 | import org.apache.maven.settings.crypto.SettingsDecrypter; 37 | import org.apache.maven.settings.crypto.SettingsDecryptionResult; 38 | import org.codehaus.plexus.PlexusConstants; 39 | import org.codehaus.plexus.PlexusContainer; 40 | import org.codehaus.plexus.component.annotations.Requirement; 41 | import org.codehaus.plexus.component.repository.exception.ComponentLookupException; 42 | import org.codehaus.plexus.context.Context; 43 | import org.codehaus.plexus.context.ContextException; 44 | import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; 45 | 46 | import java.io.IOException; 47 | import java.net.InetSocketAddress; 48 | import java.net.MalformedURLException; 49 | import java.net.URL; 50 | import java.text.MessageFormat; 51 | import java.util.List; 52 | import org.eclipse.egit.github.core.client.IGitHubConstants; 53 | 54 | /** 55 | * Base GitHub Mojo class to be extended. 56 | * 57 | * @author Kevin Sawicki (kevin@github.com) 58 | */ 59 | public abstract class GitHubProjectMojo extends AbstractMojo implements Contextualizable { 60 | 61 | /** 62 | * Get formatted exception message for {@link IOException} 63 | * 64 | * @param e 65 | * @return message 66 | */ 67 | public static String getExceptionMessage(IOException e) { 68 | return e.getMessage(); 69 | } 70 | 71 | /** 72 | * Is debug logging enabled? 73 | * 74 | * @return true if enabled, false otherwise 75 | */ 76 | protected boolean isDebug() { 77 | final Log log = getLog(); 78 | return log != null ? log.isDebugEnabled() : false; 79 | } 80 | 81 | /** 82 | * Is info logging enabled? 83 | * 84 | * @return true if enabled, false otherwise 85 | */ 86 | protected boolean isInfo() { 87 | final Log log = getLog(); 88 | return log != null ? log.isInfoEnabled() : false; 89 | } 90 | 91 | /** 92 | * Log given message at debug level 93 | * 94 | * @param message 95 | */ 96 | protected void debug(String message) { 97 | final Log log = getLog(); 98 | if (log != null) 99 | log.debug(message); 100 | } 101 | 102 | /** 103 | * Log given message and throwable at debug level 104 | * 105 | * @param message 106 | * @param throwable 107 | */ 108 | protected void debug(String message, Throwable throwable) { 109 | final Log log = getLog(); 110 | if (log != null) 111 | log.debug(message, throwable); 112 | } 113 | 114 | /** 115 | * Log given message at info level 116 | * 117 | * @param message 118 | */ 119 | protected void info(String message) { 120 | final Log log = getLog(); 121 | if (log != null) 122 | log.info(message); 123 | } 124 | 125 | /** 126 | * Log given message and throwable at info level 127 | * 128 | * @param message 129 | * @param throwable 130 | */ 131 | protected void info(String message, Throwable throwable) { 132 | final Log log = getLog(); 133 | if (log != null) 134 | log.info(message, throwable); 135 | } 136 | 137 | /** 138 | * Create client 139 | * 140 | * @param host 141 | * @param userName 142 | * @param password 143 | * @param oauth2Token 144 | * @param serverId 145 | * @param settings 146 | * @param session 147 | * @return client 148 | * @throws MojoExecutionException 149 | */ 150 | protected GitHubClient createClient(String host, String userName, 151 | String password, String oauth2Token, String serverId, 152 | Settings settings, MavenSession session) 153 | throws MojoExecutionException { 154 | GitHubClient client; 155 | if (!StringUtils.isEmpty(host)) { 156 | if (isDebug()) 157 | debug("Using custom host: " + host); 158 | client = createClient(host); 159 | } else 160 | client = createClient(); 161 | 162 | { 163 | Proxy proxy = getProxy( settings, serverId, host ); 164 | if ( null != proxy ) 165 | { 166 | try 167 | { 168 | SettingsDecrypter settingsDecrypter = container.lookup( SettingsDecrypter.class ); 169 | SettingsDecryptionResult result = 170 | settingsDecrypter.decrypt( new DefaultSettingsDecryptionRequest( proxy ) ); 171 | proxy = result.getProxy(); 172 | } 173 | catch ( ComponentLookupException cle ) 174 | { 175 | throw new MojoExecutionException( "Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle ); 176 | } 177 | } 178 | 179 | if ( null != proxy ){ 180 | java.net.Proxy javaProxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress( proxy.getHost(), proxy.getPort())); 181 | if (isDebug()) 182 | debug(MessageFormat.format("Found Proxy {0}:{1}", 183 | proxy.getHost(), proxy.getPort())); 184 | 185 | if ( client instanceof GitHubClientEgit ) 186 | { 187 | GitHubClientEgit clientEgit = (GitHubClientEgit)client; 188 | if (isDebug()) 189 | debug(MessageFormat.format("Use Proxy for Egit {0}", 190 | javaProxy)); 191 | clientEgit.setProxy( javaProxy ); 192 | } 193 | } 194 | } 195 | 196 | if (configureUsernamePassword(client, userName, password) 197 | || configureOAuth2Token(client, oauth2Token) 198 | || configureServerCredentials(client, serverId, settings, 199 | session)) 200 | return client; 201 | else 202 | throw new MojoExecutionException( 203 | "No authentication credentials configured"); 204 | } 205 | 206 | /** 207 | * Create client 208 | *

209 | * Subclasses can override to do any custom client configuration 210 | * 211 | * @param hostname 212 | * @return non-null client 213 | * @throws MojoExecutionException 214 | */ 215 | protected GitHubClient createClient(String hostname) 216 | throws MojoExecutionException { 217 | if (!hostname.contains("://")) 218 | return new RateLimitedGitHubClient(hostname); 219 | try { 220 | URL hostUrl = new URL(hostname); 221 | return new RateLimitedGitHubClient(hostUrl.getHost(), hostUrl.getPort(), 222 | hostUrl.getProtocol()); 223 | } catch (MalformedURLException e) { 224 | throw new MojoExecutionException("Could not parse host URL " 225 | + hostname, e); 226 | } 227 | } 228 | 229 | /** 230 | * Create client 231 | *

232 | * Subclasses can override to do any custom client configuration 233 | * 234 | * @return non-null client 235 | */ 236 | protected GitHubClient createClient() { 237 | return new RateLimitedGitHubClient(); 238 | } 239 | 240 | /** 241 | * Configure credentials from configured username/password combination 242 | * 243 | * @param client 244 | * @param userName 245 | * @param password 246 | * @return true if configured, false otherwise 247 | */ 248 | protected boolean configureUsernamePassword(final GitHubClient client, 249 | final String userName, final String password) { 250 | if (StringUtils.isEmpty(userName, password)) 251 | return false; 252 | 253 | if (isDebug()) 254 | debug("Using basic authentication with username: " + userName); 255 | client.setCredentials(userName, password); 256 | return true; 257 | } 258 | 259 | /** 260 | * Configure credentials from configured OAuth2 token 261 | * 262 | * @param client 263 | * @param oauth2Token 264 | * @return true if configured, false otherwise 265 | */ 266 | protected boolean configureOAuth2Token(final GitHubClient client, 267 | final String oauth2Token) { 268 | if (StringUtils.isEmpty(oauth2Token)) 269 | return false; 270 | 271 | if (isDebug()) 272 | debug("Using OAuth2 access token authentication"); 273 | client.setOAuth2Token(oauth2Token); 274 | return true; 275 | } 276 | 277 | /** 278 | * Configure client with credentials from given server id 279 | * 280 | * @param client 281 | * @param serverId 282 | * @param settings 283 | * @param session 284 | * @return true if configured, false otherwise 285 | * @throws MojoExecutionException 286 | */ 287 | protected boolean configureServerCredentials(final GitHubClient client, 288 | final String serverId, final Settings settings, 289 | final MavenSession session) throws MojoExecutionException { 290 | if (StringUtils.isEmpty(serverId)) 291 | return false; 292 | 293 | String serverUsername = null; 294 | String serverPassword = null; 295 | 296 | // Maven 3.1.0 - It's now impossible to retrieve the username and password from the remote repository. 297 | 298 | // if (session != null) { 299 | // RepositorySystemSession systemSession = session 300 | // .getRepositorySession(); 301 | // if (systemSession != null) { 302 | // RemoteRepository.Builder builder = new RemoteRepository.Builder(serverId, "", ""); 303 | // Authentication authInfo = systemSession.getAuthenticationSelector().getAuthentication 304 | // (builder.build()); 305 | // if (authInfo != null) { 306 | // serverUsername = authInfo.getUsername(); 307 | // serverPassword = authInfo.getPassword(); 308 | // } 309 | // } 310 | // } 311 | 312 | // Always true. 313 | // if (StringUtils.isEmpty(serverPassword)) { 314 | Server server = getServer(settings, serverId); 315 | if (server == null) 316 | throw new MojoExecutionException(MessageFormat.format( 317 | "Server ''{0}'' not found in settings", serverId)); 318 | 319 | if (isDebug()) 320 | debug(MessageFormat.format("Using ''{0}'' server credentials", 321 | serverId)); 322 | 323 | { 324 | try 325 | { 326 | SettingsDecrypter settingsDecrypter = container.lookup( SettingsDecrypter.class ); 327 | SettingsDecryptionResult result = 328 | settingsDecrypter.decrypt( new DefaultSettingsDecryptionRequest( server ) ); 329 | server = result.getServer(); 330 | } 331 | catch ( ComponentLookupException cle ) 332 | { 333 | throw new MojoExecutionException( "Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle ); 334 | } 335 | } 336 | 337 | serverUsername = server.getUsername(); 338 | serverPassword = server.getPassword(); 339 | // } 340 | 341 | if (!StringUtils.isEmpty(serverUsername, serverPassword)) { 342 | if (isDebug()) 343 | debug("Using basic authentication with username: " 344 | + serverUsername); 345 | client.setCredentials(serverUsername, serverPassword); 346 | return true; 347 | } 348 | 349 | // A server password without a username is assumed to be an OAuth2 token 350 | if (!StringUtils.isEmpty(serverPassword)) { 351 | if (isDebug()) 352 | debug("Using OAuth2 access token authentication"); 353 | client.setOAuth2Token(serverPassword); 354 | return true; 355 | } 356 | 357 | if (isDebug()) 358 | debug(MessageFormat.format( 359 | "Server ''{0}'' is missing username/password credentials", 360 | serverId)); 361 | return false; 362 | } 363 | 364 | /** 365 | * Get repository and throw a {@link MojoExecutionException} on failures 366 | * 367 | * @param project 368 | * @param owner 369 | * @param name 370 | * @return non-null repository id 371 | * @throws MojoExecutionException 372 | */ 373 | protected RepositoryId getRepository(final MavenProject project, 374 | final String owner, final String name) 375 | throws MojoExecutionException { 376 | RepositoryId repository = RepositoryUtils.getRepository(project, owner, 377 | name); 378 | if (repository == null) 379 | throw new MojoExecutionException( 380 | "No GitHub repository (owner and name) configured"); 381 | if (isDebug()) 382 | debug(MessageFormat.format("Using GitHub repository {0}", 383 | repository.generateId())); 384 | return repository; 385 | } 386 | 387 | /** 388 | * Get server with given id 389 | * 390 | * @param settings 391 | * @param serverId 392 | * must be non-null and non-empty 393 | * @return server or null if none matching 394 | */ 395 | protected Server getServer(final Settings settings, final String serverId) { 396 | if (settings == null) 397 | return null; 398 | List servers = settings.getServers(); 399 | if (servers == null || servers.isEmpty()) 400 | return null; 401 | 402 | for (Server server : servers) 403 | if (serverId.equals(server.getId())) 404 | return server; 405 | return null; 406 | } 407 | 408 | /** 409 | * Check hostname that matched nonProxy setting 410 | * 411 | * @param proxy Maven Proxy. Must not null 412 | * @param hostname 413 | * @return matching result. true: match nonProxy 414 | */ 415 | protected boolean matchNonProxy( final Proxy proxy, final String hostname ) 416 | { 417 | String host = hostname; 418 | 419 | if ( null == hostname ) 420 | host = IGitHubConstants.HOST_DEFAULT; // IGitHubConstants.HOST_API; 421 | 422 | // code from org.apache.maven.plugins.site.AbstractDeployMojo#getProxyInfo 423 | final String nonProxyHosts = proxy.getNonProxyHosts(); 424 | if ( null != nonProxyHosts ) 425 | { 426 | final String[] nonProxies = nonProxyHosts.split( "(,)|(;)|(\\|)" ); 427 | if ( null != nonProxies ) 428 | { 429 | for ( final String nonProxyHost : nonProxies ) 430 | { 431 | //if ( StringUtils.contains( nonProxyHost, "*" ) ) 432 | if ( null != nonProxyHost && nonProxyHost.contains( "*" ) ) 433 | { 434 | // Handle wildcard at the end, beginning or middle of the nonProxyHost 435 | final int pos = nonProxyHost.indexOf( '*' ); 436 | String nonProxyHostPrefix = nonProxyHost.substring( 0, pos ); 437 | String nonProxyHostSuffix = nonProxyHost.substring( pos + 1 ); 438 | // prefix* 439 | if ( !StringUtils.isEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix ) 440 | && StringUtils.isEmpty( nonProxyHostSuffix ) ) 441 | { 442 | return true; 443 | } 444 | // *suffix 445 | if ( StringUtils.isEmpty( nonProxyHostPrefix ) && !StringUtils.isEmpty( nonProxyHostSuffix ) 446 | && host.endsWith( nonProxyHostSuffix ) ) 447 | { 448 | return true; 449 | } 450 | // prefix*suffix 451 | if ( !StringUtils.isEmpty( nonProxyHostPrefix ) && host.startsWith( nonProxyHostPrefix ) 452 | && !StringUtils.isEmpty( nonProxyHostSuffix ) && host.endsWith( nonProxyHostSuffix ) ) 453 | { 454 | return true; 455 | } 456 | } 457 | else if ( host.equals( nonProxyHost ) ) 458 | { 459 | return true; 460 | } 461 | } 462 | } 463 | } 464 | 465 | return false; 466 | } 467 | 468 | /** 469 | * Get proxy from settings 470 | * 471 | * @param settings 472 | * @param serverId 473 | * must be non-null and non-empty 474 | * @param host 475 | * hostname 476 | * @return proxy or null if none matching 477 | */ 478 | protected Proxy getProxy(final Settings settings, final String serverId, final String host) { 479 | if (settings == null) 480 | return null; 481 | List proxies = settings.getProxies(); 482 | if (proxies == null || proxies.isEmpty()) 483 | return null; 484 | 485 | // search id match first 486 | if ( serverId != null && !serverId.isEmpty() ) { 487 | for (Proxy proxy : proxies) { 488 | if ( proxy.isActive() ) { 489 | final String proxyId = proxy.getId(); 490 | if ( proxyId != null && !proxyId.isEmpty() ) { 491 | if ( proxyId.equalsIgnoreCase(serverId) ) { 492 | if ( ( "http".equalsIgnoreCase( proxy.getProtocol() ) || "https".equalsIgnoreCase( proxy.getProtocol() ) ) ) { 493 | if ( matchNonProxy( proxy, host ) ) 494 | return null; 495 | else 496 | return proxy; 497 | } 498 | } 499 | } 500 | } 501 | } 502 | } 503 | 504 | // search active proxy 505 | for (Proxy proxy : proxies) 506 | if ( proxy.isActive() && 507 | ( "http".equalsIgnoreCase( proxy.getProtocol() ) || "https".equalsIgnoreCase( proxy.getProtocol() ) ) 508 | ) 509 | { 510 | if ( matchNonProxy( proxy, host ) ) 511 | return null; 512 | else 513 | return proxy; 514 | } 515 | 516 | return null; 517 | } 518 | 519 | @Requirement 520 | private PlexusContainer container; 521 | 522 | /** 523 | * {@inheritDoc} 524 | */ 525 | public void contextualize( Context context ) 526 | throws ContextException 527 | { 528 | container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); 529 | } 530 | 531 | } 532 | -------------------------------------------------------------------------------- /github-core/src/main/java/com/github/maven/plugins/core/PathUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import org.codehaus.plexus.util.DirectoryScanner; 25 | 26 | /** 27 | * Path utilities 28 | * 29 | * @author Kevin Sawicki (kevin@github.com) 30 | */ 31 | public class PathUtils { 32 | 33 | /** 34 | * Get matching paths found in given base directory 35 | * 36 | * @param includes 37 | * @param excludes 38 | * @param baseDir 39 | * @return non-null but possibly empty array of string paths relative to the 40 | * base directory 41 | */ 42 | public static String[] getMatchingPaths(final String[] includes, 43 | final String[] excludes, final String baseDir) { 44 | final DirectoryScanner scanner = new DirectoryScanner(); 45 | scanner.setBasedir(baseDir); 46 | if (includes != null && includes.length > 0) 47 | scanner.setIncludes(includes); 48 | if (excludes != null && excludes.length > 0) 49 | scanner.setExcludes(excludes); 50 | scanner.scan(); 51 | return scanner.getIncludedFiles(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /github-core/src/main/java/com/github/maven/plugins/core/RateLimitedGitHubClient.java: -------------------------------------------------------------------------------- 1 | package com.github.maven.plugins.core; 2 | 3 | import com.github.maven.plugins.core.egit.GitHubClientEgit; 4 | import com.google.common.util.concurrent.RateLimiter; 5 | 6 | import java.io.IOException; 7 | import java.net.HttpURLConnection; 8 | 9 | public class RateLimitedGitHubClient extends GitHubClientEgit { 10 | 11 | /** 12 | * AS per https://github.com/octokit/octokit.net/issues/638#issuecomment-67795998, 13 | * it seems that GitHub only allow 20 API calls per 1-minute period 14 | */ 15 | private RateLimiter rateLimiter = RateLimiter.create(20.0/60.0); 16 | 17 | public RateLimitedGitHubClient() { 18 | super(); 19 | } 20 | 21 | public RateLimitedGitHubClient(String hostname) { 22 | super(hostname); 23 | } 24 | 25 | public RateLimitedGitHubClient(String hostname, int port, String scheme) { 26 | super(hostname, port, scheme); 27 | } 28 | 29 | @Override 30 | protected HttpURLConnection createDelete(String uri) throws IOException { 31 | //rateLimiter.acquire(); 32 | return super.createDelete(uri); 33 | } 34 | 35 | @Override 36 | protected HttpURLConnection createGet(String uri) throws IOException { 37 | //rateLimiter.acquire(); 38 | return super.createGet(uri); 39 | } 40 | 41 | @Override 42 | protected HttpURLConnection createPost(String uri) throws IOException { 43 | rateLimiter.acquire(); 44 | return super.createPost(uri); 45 | } 46 | 47 | @Override 48 | protected HttpURLConnection createPut(String uri) throws IOException { 49 | rateLimiter.acquire(); 50 | return super.createPut(uri); 51 | } 52 | } -------------------------------------------------------------------------------- /github-core/src/main/java/com/github/maven/plugins/core/RepositoryUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import static org.eclipse.egit.github.core.client.IGitHubConstants.HOST_DEFAULT; 25 | import static org.eclipse.egit.github.core.client.IGitHubConstants.SUFFIX_GIT; 26 | 27 | import org.apache.maven.model.Scm; 28 | import org.apache.maven.project.MavenProject; 29 | import org.eclipse.egit.github.core.RepositoryId; 30 | 31 | /** 32 | * Repository utilities 33 | * 34 | * @author Kevin Sawicki (kevin@github.com) 35 | */ 36 | public class RepositoryUtils { 37 | 38 | /** 39 | * Extra repository id from given SCM URL 40 | * 41 | * @param url 42 | * @return repository id or null if extraction fails 43 | */ 44 | public static RepositoryId extractRepositoryFromScmUrl(String url) { 45 | if (StringUtils.isEmpty(url)) 46 | return null; 47 | int ghIndex = url.indexOf(HOST_DEFAULT); 48 | if (ghIndex == -1 || ghIndex + 1 >= url.length()) 49 | return null; 50 | if (!url.endsWith(SUFFIX_GIT)) 51 | return null; 52 | url = url.substring(ghIndex + HOST_DEFAULT.length() + 1, url.length() 53 | - SUFFIX_GIT.length()); 54 | return RepositoryId.createFromId(url); 55 | } 56 | 57 | /** 58 | * Get repository 59 | * 60 | * @param project 61 | * @param owner 62 | * @param name 63 | * 64 | * @return repository id or null if none configured 65 | */ 66 | public static RepositoryId getRepository(final MavenProject project, 67 | final String owner, final String name) { 68 | // Use owner and name if specified 69 | if (!StringUtils.isEmpty(owner, name)) 70 | return RepositoryId.create(owner, name); 71 | 72 | if (project == null) 73 | return null; 74 | 75 | RepositoryId repo = null; 76 | // Extract repository from SCM URLs first if present 77 | final Scm scm = project.getScm(); 78 | if (scm != null) { 79 | repo = RepositoryId.createFromUrl(scm.getUrl()); 80 | if (repo == null) 81 | repo = extractRepositoryFromScmUrl(scm.getConnection()); 82 | if (repo == null) 83 | repo = extractRepositoryFromScmUrl(scm.getDeveloperConnection()); 84 | } 85 | 86 | // Check project URL last 87 | if (repo == null) 88 | repo = RepositoryId.createFromUrl(project.getUrl()); 89 | 90 | return repo; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /github-core/src/main/java/com/github/maven/plugins/core/StringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * String utilities 29 | * 30 | * @author Kevin Sawicki (kevin@github.com) 31 | */ 32 | public class StringUtils { 33 | 34 | /** 35 | * Are any given values null or empty? 36 | * 37 | * @param values 38 | * @return true if any null or empty, false otherwise 39 | */ 40 | public static boolean isEmpty(final String... values) { 41 | if (values == null || values.length == 0) 42 | return true; 43 | for (String value : values) 44 | if (value == null || value.length() == 0) 45 | return true; 46 | return false; 47 | } 48 | 49 | /** 50 | * Create an array with only the non-null and non-empty values 51 | * 52 | * @param values 53 | * @return non-null but possibly empty array of non-null/non-empty strings 54 | */ 55 | public static String[] removeEmpties(final String... values) { 56 | if (values == null || values.length == 0) 57 | return new String[0]; 58 | List validValues = new ArrayList(); 59 | for (String value : values) 60 | if (value != null && value.length() > 0) 61 | validValues.add(value); 62 | return validValues.toArray(new String[validValues.size()]); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /github-core/src/main/java/com/github/maven/plugins/core/egit/GitHubClientEgit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core.egit; 23 | 24 | import java.io.IOException; 25 | import java.net.HttpURLConnection; 26 | import java.net.Proxy; 27 | import java.net.URL; 28 | import org.eclipse.egit.github.core.client.GitHubClient; 29 | 30 | /** 31 | * GitHubClient support proxy 32 | * 33 | * @author Kiyofumi Kondoh 34 | */ 35 | public class GitHubClientEgit extends GitHubClient { 36 | 37 | public GitHubClientEgit() { 38 | super(); 39 | } 40 | 41 | public GitHubClientEgit(String hostname) { 42 | super(hostname); 43 | } 44 | 45 | public GitHubClientEgit(String hostname, int port, String scheme) { 46 | super(hostname, port, scheme); 47 | } 48 | 49 | protected Proxy proxy; 50 | 51 | public void setProxy(Proxy proxy) { 52 | this.proxy = proxy; 53 | } 54 | 55 | @Override 56 | protected HttpURLConnection createConnection(String uri) throws IOException { 57 | URL url = new URL(createUri(uri)); 58 | if ( null == proxy ) { 59 | return (HttpURLConnection) url.openConnection(); 60 | } else { 61 | return (HttpURLConnection) url.openConnection( proxy ); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /github-core/src/test/java/com/github/maven/plugins/core/ClientCredentialsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertNull; 27 | 28 | import java.util.Collections; 29 | import java.util.concurrent.atomic.AtomicReference; 30 | 31 | import org.apache.maven.execution.MavenSession; 32 | import org.apache.maven.plugin.MojoExecutionException; 33 | import org.apache.maven.plugin.MojoFailureException; 34 | import org.apache.maven.settings.Server; 35 | import org.apache.maven.settings.Settings; 36 | import org.codehaus.plexus.DefaultPlexusContainer; 37 | import org.codehaus.plexus.PlexusConstants; 38 | import org.codehaus.plexus.PlexusContainerException; 39 | import org.codehaus.plexus.context.Context; 40 | import org.codehaus.plexus.context.ContextException; 41 | import org.eclipse.egit.github.core.client.GitHubClient; 42 | import org.junit.Test; 43 | 44 | /** 45 | * Credential tests for the various configuration types 46 | * 47 | * @author Kevin Sawicki (kevin@github.com) 48 | */ 49 | public class ClientCredentialsTest { 50 | 51 | private class TestMojo extends GitHubProjectMojo { 52 | 53 | private final AtomicReference user = new AtomicReference(); 54 | 55 | private final AtomicReference password = new AtomicReference(); 56 | 57 | private final AtomicReference token = new AtomicReference(); 58 | 59 | protected GitHubClient createClient() { 60 | try 61 | { 62 | DefaultPlexusContainer container = new DefaultPlexusContainer(); 63 | Context context = container.getContext(); 64 | context.put( PlexusConstants.PLEXUS_KEY, container ); 65 | super.contextualize(context ); 66 | } 67 | catch ( PlexusContainerException pce ) 68 | { 69 | pce.printStackTrace( System.err ); 70 | } 71 | catch ( ContextException ce ) 72 | { 73 | ce.printStackTrace( System.err ); 74 | } 75 | 76 | return new GitHubClient() { 77 | public GitHubClient setCredentials(String user, String password) { 78 | TestMojo.this.user.set(user); 79 | TestMojo.this.password.set(password); 80 | return super.setCredentials(user, password); 81 | } 82 | 83 | public GitHubClient setOAuth2Token(String token) { 84 | TestMojo.this.token.set(token); 85 | return super.setOAuth2Token(token); 86 | } 87 | 88 | }; 89 | } 90 | 91 | @Override 92 | public GitHubClient createClient(String host, String userName, 93 | String password, String oauth2Token, String serverId, 94 | Settings settings, MavenSession session) 95 | throws MojoExecutionException { 96 | return super.createClient(host, userName, password, oauth2Token, 97 | serverId, settings, session); 98 | } 99 | 100 | public void execute() throws MojoExecutionException, 101 | MojoFailureException { 102 | // Intentionally left blank 103 | } 104 | } 105 | 106 | /** 107 | * Test configured client with direct user name and password 108 | * 109 | * @throws Exception 110 | */ 111 | @Test 112 | public void validUserNameAndPassword() throws Exception { 113 | TestMojo mojo = new TestMojo(); 114 | GitHubClient client = mojo.createClient(null, "a", "b", null, null, 115 | null, null); 116 | assertNotNull(client); 117 | assertEquals("a", mojo.user.get()); 118 | assertEquals("b", mojo.password.get()); 119 | assertNull(mojo.token.get()); 120 | } 121 | 122 | /** 123 | * Test configured client with no user name 124 | * 125 | * @throws Exception 126 | */ 127 | @Test(expected = MojoExecutionException.class) 128 | public void noUserName() throws Exception { 129 | TestMojo mojo = new TestMojo(); 130 | mojo.createClient(null, "a", null, null, null, null, null); 131 | } 132 | 133 | /** 134 | * Test configured client with no password 135 | * 136 | * @throws Exception 137 | */ 138 | @Test(expected = MojoExecutionException.class) 139 | public void noPassword() throws Exception { 140 | TestMojo mojo = new TestMojo(); 141 | mojo.createClient(null, null, "b", null, null, null, null); 142 | } 143 | 144 | /** 145 | * Test configured client with token 146 | * 147 | * @throws Exception 148 | */ 149 | @Test 150 | public void validOAuth2Token() throws Exception { 151 | TestMojo mojo = new TestMojo(); 152 | GitHubClient client = mojo.createClient(null, null, null, "token", 153 | null, null, null); 154 | assertNotNull(client); 155 | assertNull(mojo.user.get()); 156 | assertNull(mojo.password.get()); 157 | assertEquals(mojo.token.get(), "token"); 158 | } 159 | 160 | /** 161 | * Test configured client with token 162 | * 163 | * @throws Exception 164 | */ 165 | @Test 166 | public void validOAuth2TokenWithUsername() throws Exception { 167 | TestMojo mojo = new TestMojo(); 168 | GitHubClient client = mojo.createClient(null, "a", null, "token", null, 169 | null, null); 170 | assertNotNull(client); 171 | assertNull(mojo.user.get()); 172 | assertNull(mojo.password.get()); 173 | assertEquals(mojo.token.get(), "token"); 174 | } 175 | 176 | /** 177 | * Test configured client with server with username & password 178 | * 179 | * @throws Exception 180 | */ 181 | @Test 182 | public void validServerUsernameAndPassword() throws Exception { 183 | TestMojo mojo = new TestMojo(); 184 | Settings settings = new Settings(); 185 | Server server = new Server(); 186 | server.setId("server"); 187 | server.setUsername("a"); 188 | server.setPassword("b"); 189 | settings.addServer(server); 190 | GitHubClient client = mojo.createClient(null, null, null, null, 191 | "server", settings, null); 192 | assertNotNull(client); 193 | assertEquals("a", mojo.user.get()); 194 | assertEquals("b", mojo.password.get()); 195 | assertNull(mojo.token.get()); 196 | } 197 | 198 | /** 199 | * Test configured client with server and no username & password 200 | * 201 | * @throws Exception 202 | */ 203 | @Test(expected = MojoExecutionException.class) 204 | public void noServerUsernameAndPassword() throws Exception { 205 | TestMojo mojo = new TestMojo(); 206 | Settings settings = new Settings(); 207 | Server server = new Server(); 208 | server.setId("server"); 209 | server.setUsername(""); 210 | server.setPassword(""); 211 | settings.addServer(server); 212 | mojo.createClient(null, null, null, null, "server", settings, null); 213 | } 214 | 215 | /** 216 | * Test configured client with server with OAuth 2 token 217 | * 218 | * @throws Exception 219 | */ 220 | @Test 221 | public void validServerToken() throws Exception { 222 | TestMojo mojo = new TestMojo(); 223 | Settings settings = new Settings(); 224 | Server server = new Server(); 225 | server.setId("server"); 226 | server.setPassword("b"); 227 | settings.addServer(server); 228 | GitHubClient client = mojo.createClient(null, null, null, null, 229 | "server", settings, null); 230 | assertNotNull(client); 231 | assertNull(mojo.user.get()); 232 | assertNull(mojo.password.get()); 233 | assertEquals("b", mojo.token.get()); 234 | } 235 | 236 | /** 237 | * Test configured client with missing server 238 | * 239 | * @throws Exception 240 | */ 241 | @Test(expected = MojoExecutionException.class) 242 | public void missingServerNoSettings() throws Exception { 243 | TestMojo mojo = new TestMojo(); 244 | mojo.createClient(null, null, null, null, "server", null, null); 245 | } 246 | 247 | /** 248 | * Test configured client with missing server 249 | * 250 | * @throws Exception 251 | */ 252 | @Test(expected = MojoExecutionException.class) 253 | public void missingServerNullServers() throws Exception { 254 | TestMojo mojo = new TestMojo(); 255 | Settings settings = new Settings(); 256 | mojo.createClient(null, null, null, null, "server", settings, null); 257 | } 258 | 259 | /** 260 | * Test configured client with missing server 261 | * 262 | * @throws Exception 263 | */ 264 | @Test(expected = MojoExecutionException.class) 265 | public void missingServerEmptyServers() throws Exception { 266 | TestMojo mojo = new TestMojo(); 267 | Settings settings = new Settings(); 268 | settings.setServers(Collections. emptyList()); 269 | mojo.createClient(null, null, null, null, "server", settings, null); 270 | } 271 | 272 | /** 273 | * Test configured client with missing server 274 | * 275 | * @throws Exception 276 | */ 277 | @Test(expected = MojoExecutionException.class) 278 | public void missingServerNoMatching() throws Exception { 279 | TestMojo mojo = new TestMojo(); 280 | Settings settings = new Settings(); 281 | Server server = new Server(); 282 | server.setId("server2"); 283 | server.setPassword("b"); 284 | settings.addServer(server); 285 | mojo.createClient(null, null, null, null, "server", settings, null); 286 | } 287 | 288 | /** 289 | * Test configured client with no configuration 290 | * 291 | * @throws Exception 292 | */ 293 | @Test(expected = MojoExecutionException.class) 294 | public void noConfiguration() throws Exception { 295 | TestMojo mojo = new TestMojo(); 296 | mojo.createClient(null, null, null, null, null, null, null); 297 | } 298 | 299 | /** 300 | * Test configured client with no configuration 301 | * 302 | * @throws Exception 303 | */ 304 | @Test(expected = MojoExecutionException.class) 305 | public void noConfigurationWithSettings() throws Exception { 306 | TestMojo mojo = new TestMojo(); 307 | Settings settings = new Settings(); 308 | mojo.createClient(null, null, null, null, null, settings, null); 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /github-core/src/test/java/com/github/maven/plugins/core/CustomHostnameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertNull; 27 | 28 | import java.util.concurrent.atomic.AtomicReference; 29 | 30 | import org.apache.maven.execution.MavenSession; 31 | import org.apache.maven.plugin.MojoExecutionException; 32 | import org.apache.maven.plugin.MojoFailureException; 33 | import org.apache.maven.settings.Settings; 34 | import org.eclipse.egit.github.core.client.GitHubClient; 35 | import org.junit.Test; 36 | 37 | /** 38 | * Tests using client with custom hostname 39 | * 40 | * @author Kevin Sawicki (kevin@github.com) 41 | */ 42 | public class CustomHostnameTest { 43 | 44 | private class TestMojo extends GitHubProjectMojo { 45 | 46 | private final AtomicReference host = new AtomicReference(); 47 | 48 | protected GitHubClient createClient() { 49 | host.set(null); 50 | return super.createClient(); 51 | } 52 | 53 | protected GitHubClient createClient(String hostname) 54 | throws MojoExecutionException { 55 | host.set(hostname); 56 | return super.createClient(hostname); 57 | } 58 | 59 | public GitHubClient createClient(String host, String userName, 60 | String password, String oauth2Token, String serverId, 61 | Settings settings, MavenSession session) 62 | throws MojoExecutionException { 63 | return super.createClient(host, userName, password, oauth2Token, 64 | serverId, settings, session); 65 | } 66 | 67 | public void execute() throws MojoExecutionException, 68 | MojoFailureException { 69 | // Intentionally left blank 70 | } 71 | } 72 | 73 | /** 74 | * Test custom hostname 75 | * 76 | * @throws Exception 77 | */ 78 | @Test 79 | public void validHostname() throws Exception { 80 | TestMojo mojo = new TestMojo(); 81 | GitHubClient client = mojo.createClient("h", "a", "b", null, null, 82 | null, null); 83 | assertNotNull(client); 84 | assertEquals("h", mojo.host.get()); 85 | } 86 | 87 | /** 88 | * Test null custom hostname 89 | * 90 | * @throws Exception 91 | */ 92 | @Test 93 | public void nullHostname() throws Exception { 94 | TestMojo mojo = new TestMojo(); 95 | GitHubClient client = mojo.createClient(null, "a", "b", null, null, 96 | null, null); 97 | assertNotNull(client); 98 | assertNull(mojo.host.get()); 99 | } 100 | 101 | /** 102 | * Test empty custom hostname 103 | * 104 | * @throws Exception 105 | */ 106 | @Test 107 | public void emptyHost() throws Exception { 108 | TestMojo mojo = new TestMojo(); 109 | GitHubClient client = mojo.createClient("", "a", "b", null, null, null, 110 | null); 111 | assertNotNull(client); 112 | assertNull(mojo.host.get()); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /github-core/src/test/java/com/github/maven/plugins/core/MatchNonProxyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import java.io.File; 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertNull; 27 | import static org.junit.Assert.assertTrue; 28 | import static org.junit.Assert.assertFalse; 29 | 30 | import java.util.concurrent.atomic.AtomicReference; 31 | 32 | import org.apache.maven.execution.MavenSession; 33 | import org.apache.maven.plugin.MojoExecutionException; 34 | import org.apache.maven.plugin.MojoFailureException; 35 | import org.apache.maven.settings.Proxy; 36 | import org.apache.maven.settings.Settings; 37 | import org.apache.maven.settings.building.DefaultSettingsBuilderFactory; 38 | import org.apache.maven.settings.building.DefaultSettingsBuildingRequest; 39 | import org.apache.maven.settings.building.FileSettingsSource; 40 | import org.apache.maven.settings.building.SettingsBuilder; 41 | import org.apache.maven.settings.building.SettingsBuildingResult; 42 | import org.eclipse.egit.github.core.client.GitHubClient; 43 | import org.eclipse.egit.github.core.client.IGitHubConstants; 44 | import org.junit.Test; 45 | 46 | /** 47 | * NonProxy tests for the various configuration 48 | * 49 | * @author Kiyofumi Kondoh 50 | */ 51 | public class MatchNonProxyTest { 52 | 53 | private class TestMojo extends GitHubProjectMojo { 54 | 55 | private final AtomicReference host = new AtomicReference(); 56 | 57 | protected GitHubClient createClient() { 58 | host.set(null); 59 | return super.createClient(); 60 | } 61 | 62 | protected GitHubClient createClient(String hostname) 63 | throws MojoExecutionException { 64 | host.set(hostname); 65 | return super.createClient(hostname); 66 | } 67 | 68 | public GitHubClient createClient(String host, String userName, 69 | String password, String oauth2Token, String serverId, 70 | Settings settings, MavenSession session) 71 | throws MojoExecutionException { 72 | return super.createClient(host, userName, password, oauth2Token, 73 | serverId, settings, session); 74 | } 75 | 76 | public void execute() throws MojoExecutionException, 77 | MojoFailureException { 78 | // Intentionally left blank 79 | } 80 | } 81 | 82 | /** 83 | * matchNonProxy tests with single nonProxyHosts 84 | */ 85 | @Test 86 | public void matchNonProxyWithSingle_nonPorxyHosts() throws Exception 87 | { 88 | SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance(); 89 | assertNotNull( builder ); 90 | 91 | DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); 92 | request.setSystemProperties( System.getProperties() ); 93 | FileSettingsSource fileSource = new FileSettingsSource( new File("src/test/resources/settings/proxy/nonproxy-github.xml").getAbsoluteFile() ); 94 | request.setUserSettingsSource( fileSource ); 95 | 96 | SettingsBuildingResult result = builder.build( request ); 97 | assertNotNull( result ); 98 | assertNotNull( result.getEffectiveSettings() ); 99 | 100 | TestMojo mojo = new TestMojo(); 101 | assertNotNull( mojo ); 102 | 103 | assertNotNull( result.getEffectiveSettings().getProxies() ); 104 | for ( final Proxy proxy : result.getEffectiveSettings().getProxies() ) 105 | { 106 | { 107 | final boolean isNonProxy = mojo.matchNonProxy( proxy, IGitHubConstants.HOST_DEFAULT ); 108 | assertTrue( isNonProxy ); 109 | } 110 | { 111 | final boolean isNonProxy = mojo.matchNonProxy( proxy, IGitHubConstants.HOST_API ); 112 | assertFalse( isNonProxy ); 113 | } 114 | { 115 | final boolean isNonProxy = mojo.matchNonProxy( proxy, "hoge." + IGitHubConstants.HOST_DEFAULT ); 116 | assertFalse( isNonProxy ); 117 | } 118 | { 119 | final boolean isNonProxy = mojo.matchNonProxy( proxy, "hoge" + IGitHubConstants.HOST_DEFAULT ); 120 | assertFalse( isNonProxy ); 121 | } 122 | { 123 | final boolean isNonProxy = mojo.matchNonProxy( proxy, mojo.host.get() ); 124 | assertTrue( isNonProxy ); 125 | } 126 | } 127 | } 128 | 129 | /** 130 | * matchNonProxy tests with multiple nonProxyHosts 131 | */ 132 | @Test 133 | public void matchNonProxyWithMultiple_nonPorxyHosts() throws Exception 134 | { 135 | SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance(); 136 | assertNotNull( builder ); 137 | 138 | DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); 139 | request.setSystemProperties( System.getProperties() ); 140 | FileSettingsSource fileSource = new FileSettingsSource( new File("src/test/resources/settings/proxy/nonproxy-github_and_api.xml").getAbsoluteFile() ); 141 | request.setUserSettingsSource( fileSource ); 142 | 143 | SettingsBuildingResult result = builder.build( request ); 144 | assertNotNull( result ); 145 | assertNotNull( result.getEffectiveSettings() ); 146 | 147 | TestMojo mojo = new TestMojo(); 148 | assertNotNull( mojo ); 149 | 150 | assertNotNull( result.getEffectiveSettings().getProxies() ); 151 | for ( final Proxy proxy : result.getEffectiveSettings().getProxies() ) 152 | { 153 | { 154 | final boolean isNonProxy = mojo.matchNonProxy( proxy, IGitHubConstants.HOST_DEFAULT ); 155 | assertTrue( isNonProxy ); 156 | } 157 | { 158 | final boolean isNonProxy = mojo.matchNonProxy( proxy, IGitHubConstants.HOST_API ); 159 | assertTrue( isNonProxy ); 160 | } 161 | { 162 | final boolean isNonProxy = mojo.matchNonProxy( proxy, "hoge." + IGitHubConstants.HOST_DEFAULT ); 163 | assertFalse( isNonProxy ); 164 | } 165 | { 166 | final boolean isNonProxy = mojo.matchNonProxy( proxy, "hoge" + IGitHubConstants.HOST_DEFAULT ); 167 | assertFalse( isNonProxy ); 168 | } 169 | { 170 | final boolean isNonProxy = mojo.matchNonProxy( proxy, mojo.host.get() ); 171 | assertTrue( isNonProxy ); 172 | } 173 | } 174 | } 175 | 176 | /** 177 | * matchNonProxy tests with wildcard nonProxyHosts 178 | */ 179 | @Test 180 | public void matchNonProxyWithWildcard_nonPorxyHosts() throws Exception 181 | { 182 | SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance(); 183 | assertNotNull( builder ); 184 | 185 | DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); 186 | request.setSystemProperties( System.getProperties() ); 187 | FileSettingsSource fileSource = new FileSettingsSource( new File("src/test/resources/settings/proxy/nonproxy-github_wildcard.xml").getAbsoluteFile() ); 188 | request.setUserSettingsSource( fileSource ); 189 | 190 | SettingsBuildingResult result = builder.build( request ); 191 | assertNotNull( result ); 192 | assertNotNull( result.getEffectiveSettings() ); 193 | 194 | TestMojo mojo = new TestMojo(); 195 | assertNotNull( mojo ); 196 | 197 | assertNotNull( result.getEffectiveSettings().getProxies() ); 198 | for ( final Proxy proxy : result.getEffectiveSettings().getProxies() ) 199 | { 200 | { 201 | final boolean isNonProxy = mojo.matchNonProxy( proxy, IGitHubConstants.HOST_DEFAULT ); 202 | assertTrue( isNonProxy ); 203 | } 204 | { 205 | final boolean isNonProxy = mojo.matchNonProxy( proxy, IGitHubConstants.HOST_API ); 206 | assertTrue( isNonProxy ); 207 | } 208 | { 209 | final boolean isNonProxy = mojo.matchNonProxy( proxy, "hoge." + IGitHubConstants.HOST_DEFAULT ); 210 | assertTrue( isNonProxy ); 211 | } 212 | { 213 | final boolean isNonProxy = mojo.matchNonProxy( proxy, "hoge" + IGitHubConstants.HOST_DEFAULT ); 214 | assertTrue( isNonProxy ); 215 | } 216 | { 217 | final boolean isNonProxy = mojo.matchNonProxy( proxy, mojo.host.get() ); 218 | assertTrue( isNonProxy ); 219 | } 220 | } 221 | } 222 | 223 | 224 | 225 | 226 | /** 227 | * getProxy tests with single nonProxyHosts 228 | */ 229 | @Test 230 | public void getProxyWithSingle_nonProxyHosts() throws Exception 231 | { 232 | SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance(); 233 | assertNotNull( builder ); 234 | 235 | DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); 236 | request.setSystemProperties( System.getProperties() ); 237 | FileSettingsSource fileSource = new FileSettingsSource( new File("src/test/resources/settings/proxy/nonproxy-github.xml").getAbsoluteFile() ); 238 | request.setUserSettingsSource( fileSource ); 239 | 240 | SettingsBuildingResult result = builder.build( request ); 241 | assertNotNull( result ); 242 | assertNotNull( result.getEffectiveSettings() ); 243 | 244 | TestMojo mojo = new TestMojo(); 245 | assertNotNull( mojo ); 246 | 247 | { 248 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", mojo.host.get() ); 249 | assertNull( proxy ); 250 | } 251 | { 252 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", "intra-github.com" ); 253 | assertNotNull( proxy ); 254 | } 255 | } 256 | 257 | /** 258 | * getProxy tests with nonProxyHosts, which have same id 259 | */ 260 | @Test 261 | public void getProxyIntraWithSameId() throws Exception 262 | { 263 | SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance(); 264 | assertNotNull( builder ); 265 | 266 | DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); 267 | request.setSystemProperties( System.getProperties() ); 268 | FileSettingsSource fileSource = new FileSettingsSource( new File("src/test/resources/settings/proxy/nonproxy-intra_github.xml").getAbsoluteFile() ); 269 | request.setUserSettingsSource( fileSource ); 270 | 271 | SettingsBuildingResult result = builder.build( request ); 272 | assertNotNull( result ); 273 | assertNotNull( result.getEffectiveSettings() ); 274 | 275 | TestMojo mojo = new TestMojo(); 276 | assertNotNull( mojo ); 277 | 278 | { 279 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", mojo.host.get() ); 280 | assertNotNull( proxy ); 281 | } 282 | { 283 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", "intra-github.com" ); 284 | assertNull( proxy ); 285 | } 286 | { 287 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", "intra_github.com" ); 288 | assertNotNull( proxy ); 289 | } 290 | } 291 | 292 | /** 293 | * getProxy tests with nonProxyHosts, which doesn't have same id 294 | */ 295 | @Test 296 | public void getProxyIntraNoSameId() throws Exception 297 | { 298 | SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance(); 299 | assertNotNull( builder ); 300 | 301 | DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); 302 | request.setSystemProperties( System.getProperties() ); 303 | FileSettingsSource fileSource = new FileSettingsSource( new File("src/test/resources/settings/proxy/nonproxy-intra_github-no_same_id.xml").getAbsoluteFile() ); 304 | request.setUserSettingsSource( fileSource ); 305 | 306 | SettingsBuildingResult result = builder.build( request ); 307 | assertNotNull( result ); 308 | assertNotNull( result.getEffectiveSettings() ); 309 | 310 | TestMojo mojo = new TestMojo(); 311 | assertNotNull( mojo ); 312 | 313 | { 314 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", mojo.host.get() ); 315 | assertNotNull( proxy ); 316 | } 317 | { 318 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", "intra-github.com" ); 319 | assertNull( proxy ); 320 | } 321 | { 322 | Proxy proxy = mojo.getProxy( result.getEffectiveSettings(), "intra_github-test-nonproxy", "intra_github.com" ); 323 | assertNotNull( proxy ); 324 | } 325 | } 326 | 327 | 328 | } 329 | -------------------------------------------------------------------------------- /github-core/src/test/java/com/github/maven/plugins/core/PathUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertFalse; 26 | import static org.junit.Assert.assertNotNull; 27 | import static org.junit.Assert.assertTrue; 28 | 29 | import java.io.File; 30 | import java.io.IOException; 31 | 32 | import org.junit.Test; 33 | 34 | /** 35 | * Unit tests of {@link PathUtils} 36 | * 37 | * @author Kevin Sawicki (kevin@github.com) 38 | */ 39 | public class PathUtilsTest { 40 | 41 | /** 42 | * Create temporary directory to use in a test 43 | * 44 | * @return directory that exists 45 | */ 46 | public static final File createDirectory() { 47 | String tmpDir = System.getProperty("java.io.tmpdir"); 48 | assertNotNull(tmpDir); 49 | File dir = new File(tmpDir, "test" + System.nanoTime()); 50 | assertFalse(dir.exists()); 51 | assertTrue(dir.mkdirs()); 52 | dir.deleteOnExit(); 53 | return dir; 54 | } 55 | 56 | /** 57 | * Test of {@link PathUtils#getMatchingPaths(String[], String[], String)} 58 | * 59 | * @throws IOException 60 | */ 61 | @Test 62 | public void singleInclude() throws IOException { 63 | File include = File 64 | .createTempFile("include", ".txt", createDirectory()); 65 | String[] paths = PathUtils.getMatchingPaths( 66 | new String[] { include.getName() }, null, include.getParent()); 67 | assertNotNull(paths); 68 | assertEquals(1, paths.length); 69 | assertEquals(include.getName(), paths[0]); 70 | } 71 | 72 | /** 73 | * Test of {@link PathUtils#getMatchingPaths(String[], String[], String)} 74 | * 75 | * @throws IOException 76 | */ 77 | @Test 78 | public void singleIncludeSingleExclude() throws IOException { 79 | File dir = createDirectory(); 80 | File include = File.createTempFile("include", ".filetomatch", dir); 81 | File.createTempFile("neutral", ".notmatch", dir); 82 | File exclude = File.createTempFile("exlude", ".filetomatch", dir); 83 | String[] paths = PathUtils.getMatchingPaths( 84 | new String[] { "*.filetomatch" }, 85 | new String[] { exclude.getName() }, include.getParent()); 86 | assertNotNull(paths); 87 | assertEquals(1, paths.length); 88 | assertEquals(include.getName(), paths[0]); 89 | } 90 | 91 | /** 92 | * Test of {@link PathUtils#getMatchingPaths(String[], String[], String)} 93 | * 94 | * @throws IOException 95 | */ 96 | @Test 97 | public void singleExlude() throws IOException { 98 | File dir = createDirectory(); 99 | File include = File.createTempFile("include", ".filetomatch", dir); 100 | File exclude = File.createTempFile("exlude", ".filetomatch", dir); 101 | String[] paths = PathUtils.getMatchingPaths(null, 102 | new String[] { exclude.getName() }, include.getParent()); 103 | assertNotNull(paths); 104 | assertEquals(1, paths.length); 105 | assertEquals(include.getName(), paths[0]); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /github-core/src/test/java/com/github/maven/plugins/core/RepositoryUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import static org.fest.assertions.Assertions.assertThat; 25 | import static org.junit.Assert.assertEquals; 26 | import static org.junit.Assert.assertNotNull; 27 | import static org.junit.Assert.assertNull; 28 | import static org.mockito.Mockito.when; 29 | 30 | import org.apache.maven.model.Scm; 31 | import org.apache.maven.project.MavenProject; 32 | import org.eclipse.egit.github.core.RepositoryId; 33 | import org.junit.Test; 34 | import org.mockito.Mockito; 35 | 36 | /** 37 | * Unit tests of {@link RepositoryUtils} 38 | * 39 | * @author Kevin Sawicki (kevin@github.com) 40 | */ 41 | public class RepositoryUtilsTest { 42 | 43 | /** 44 | * Test repository extraction from SCM anonymous Git URL 45 | */ 46 | @Test 47 | public void extractFromAnonymousUrl() { 48 | RepositoryId repo = RepositoryUtils 49 | .extractRepositoryFromScmUrl("scm:git:git://github.com/owner/project.git"); 50 | assertNotNull(repo); 51 | assertEquals("owner", repo.getOwner()); 52 | assertEquals("project", repo.getName()); 53 | assertEquals("owner/project", repo.generateId()); 54 | } 55 | 56 | /** 57 | * Test repository extraction from malformed URLs 58 | */ 59 | @Test 60 | public void extractFromMalformedUrls() { 61 | assertNull(RepositoryUtils 62 | .extractRepositoryFromScmUrl("scm:git:git://github.com")); 63 | assertNull(RepositoryUtils 64 | .extractRepositoryFromScmUrl("scm:git:git://github.com/")); 65 | assertNull(RepositoryUtils 66 | .extractRepositoryFromScmUrl("scm:git:git@github.com")); 67 | assertNull(RepositoryUtils 68 | .extractRepositoryFromScmUrl("scm:git:git@github.com:")); 69 | assertNull(RepositoryUtils.extractRepositoryFromScmUrl(null)); 70 | assertNull(RepositoryUtils.extractRepositoryFromScmUrl("")); 71 | assertNull(RepositoryUtils.extractRepositoryFromScmUrl(" ")); 72 | } 73 | 74 | /** 75 | * Test repository extraction from SCM SSH Git URL 76 | */ 77 | @Test 78 | public void extractFromSshUrl() { 79 | RepositoryId repo = RepositoryUtils 80 | .extractRepositoryFromScmUrl("scm:git:git@github.com:owner/project.git"); 81 | assertNotNull(repo); 82 | assertEquals("owner", repo.getOwner()); 83 | assertEquals("project", repo.getName()); 84 | assertEquals("owner/project", repo.generateId()); 85 | } 86 | 87 | @Test 88 | public void extractRepositoryFromEmptyProject() { 89 | MavenProject project = Mockito.mock(MavenProject.class); 90 | RepositoryId repositoryId = RepositoryUtils.getRepository(project, null, null); 91 | assertThat(repositoryId).isNull(); 92 | } 93 | 94 | @Test 95 | public void extractRepositoryFromEmptyProjectWithUrl() { 96 | MavenProject project = Mockito.mock(MavenProject.class); 97 | when(project.getUrl()).thenReturn("https://github.com/nanoko-project/coffee-mill-maven-plugin"); 98 | RepositoryId repositoryId = RepositoryUtils.getRepository(project, null, null); 99 | assertThat(repositoryId).isNotNull(); 100 | assertThat(repositoryId.getName()).isEqualTo("coffee-mill-maven-plugin"); 101 | assertThat(repositoryId.getOwner()).isEqualTo("nanoko-project"); 102 | } 103 | 104 | @Test 105 | public void extractRepositoryFromEmptyProjectWithSCM() { 106 | Scm scm = Mockito.mock(Scm.class); 107 | when(scm.getUrl()).thenReturn("https://github.com/nanoko-project/coffee-mill-maven-plugin"); 108 | MavenProject project = Mockito.mock(MavenProject.class); 109 | when(project.getUrl()).thenReturn("must not be used"); 110 | when(project.getScm()).thenReturn(scm); 111 | RepositoryId repositoryId = RepositoryUtils.getRepository(project, null, null); 112 | assertThat(repositoryId).isNotNull(); 113 | assertThat(repositoryId.getName()).isEqualTo("coffee-mill-maven-plugin"); 114 | assertThat(repositoryId.getOwner()).isEqualTo("nanoko-project"); 115 | } 116 | 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /github-core/src/test/java/com/github/maven/plugins/core/StringUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.core; 23 | 24 | import static org.junit.Assert.assertArrayEquals; 25 | import static org.junit.Assert.assertFalse; 26 | import static org.junit.Assert.assertTrue; 27 | 28 | import org.junit.Test; 29 | 30 | /** 31 | * Unit tests of {@link StringUtils} 32 | * 33 | * @author Kevin Sawicki (kevin@github.com) 34 | */ 35 | public class StringUtilsTest { 36 | 37 | /** 38 | * Tests of {@link StringUtils#isEmpty(String...)} 39 | */ 40 | @Test 41 | public void isEmpty() { 42 | assertTrue(StringUtils.isEmpty((String[]) null)); 43 | assertTrue(StringUtils.isEmpty(new String[0])); 44 | assertTrue(StringUtils.isEmpty((String) null)); 45 | assertTrue(StringUtils.isEmpty("")); 46 | assertTrue(StringUtils.isEmpty("content", null)); 47 | assertTrue(StringUtils.isEmpty("content", "")); 48 | assertFalse(StringUtils.isEmpty("content")); 49 | } 50 | 51 | /** 52 | * Tests of {@link StringUtils#removeEmpties(String...)} 53 | */ 54 | @Test 55 | public void removeEmpties() { 56 | assertArrayEquals(new String[0], 57 | StringUtils.removeEmpties((String[]) null)); 58 | assertArrayEquals(new String[0], 59 | StringUtils.removeEmpties((String) null)); 60 | assertArrayEquals(new String[0], StringUtils.removeEmpties("")); 61 | assertArrayEquals(new String[] { "content" }, 62 | StringUtils.removeEmpties("", "content")); 63 | assertArrayEquals(new String[] { "content" }, 64 | StringUtils.removeEmpties(null, "content")); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /github-core/src/test/resources/settings/proxy/nonproxy-github.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24 | 25 | 28 | 29 | 30 | 31 | github-test-nonproxy 32 | true 33 | http 34 | 127.0.0.1 35 | 3128 36 | github.com 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /github-core/src/test/resources/settings/proxy/nonproxy-github_and_api.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24 | 25 | 28 | 29 | 30 | 31 | github-test-nonproxy 32 | true 33 | http 34 | 127.0.0.1 35 | 3128 36 | github.com|api.github.com 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /github-core/src/test/resources/settings/proxy/nonproxy-github_wildcard.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24 | 25 | 28 | 29 | 30 | 31 | github-test-nonproxy 32 | true 33 | http 34 | 127.0.0.1 35 | 3128 36 | *github.com 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /github-core/src/test/resources/settings/proxy/nonproxy-intra_github-no_same_id.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24 | 25 | 28 | 29 | 30 | 31 | github-test-nonproxy 32 | true 33 | http 34 | 127.0.0.1 35 | 8080 36 | intra-github.com 37 | 38 | 39 | 40 | 41 | 42 | intra_github-test-nonproxy 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /github-core/src/test/resources/settings/proxy/nonproxy-intra_github.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24 | 25 | 28 | 29 | 30 | 31 | github-test-nonproxy 32 | true 33 | http 34 | 127.0.0.1 35 | 8080 36 | 37 | 38 | intra_github-test-nonproxy 39 | true 40 | http 41 | 127.0.0.1 42 | 3128 43 | intra-github.com 44 | 45 | 46 | 47 | 48 | 49 | intra_github-test-nonproxy 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /github-site-plugin/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /github-site-plugin/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | github-site-plugin 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /github-site-plugin/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Aug 08 17:58:26 PDT 2011 2 | eclipse.preferences.version=1 3 | encoding//src/main/java=UTF-8 4 | -------------------------------------------------------------------------------- /github-site-plugin/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Aug 08 17:58:26 PDT 2011 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.source=1.5 7 | -------------------------------------------------------------------------------- /github-site-plugin/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true 3 | sp_cleanup.add_default_serial_version_id=true 4 | sp_cleanup.add_generated_serial_version_id=false 5 | sp_cleanup.add_missing_annotations=false 6 | sp_cleanup.add_missing_deprecated_annotations=true 7 | sp_cleanup.add_missing_methods=false 8 | sp_cleanup.add_missing_nls_tags=false 9 | sp_cleanup.add_missing_override_annotations=true 10 | sp_cleanup.add_missing_override_annotations_interface_methods=false 11 | sp_cleanup.add_serial_version_id=false 12 | sp_cleanup.always_use_blocks=true 13 | sp_cleanup.always_use_parentheses_in_expressions=false 14 | sp_cleanup.always_use_this_for_non_static_field_access=false 15 | sp_cleanup.always_use_this_for_non_static_method_access=false 16 | sp_cleanup.convert_to_enhanced_for_loop=false 17 | sp_cleanup.correct_indentation=false 18 | sp_cleanup.format_source_code=false 19 | sp_cleanup.format_source_code_changes_only=false 20 | sp_cleanup.make_local_variable_final=false 21 | sp_cleanup.make_parameters_final=false 22 | sp_cleanup.make_private_fields_final=true 23 | sp_cleanup.make_type_abstract_if_missing_method=false 24 | sp_cleanup.make_variable_declarations_final=false 25 | sp_cleanup.never_use_blocks=false 26 | sp_cleanup.never_use_parentheses_in_expressions=true 27 | sp_cleanup.on_save_use_additional_actions=true 28 | sp_cleanup.organize_imports=false 29 | sp_cleanup.qualify_static_field_accesses_with_declaring_class=false 30 | sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true 31 | sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true 32 | sp_cleanup.qualify_static_member_accesses_with_declaring_class=false 33 | sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 34 | sp_cleanup.remove_private_constructors=true 35 | sp_cleanup.remove_trailing_whitespaces=true 36 | sp_cleanup.remove_trailing_whitespaces_all=true 37 | sp_cleanup.remove_trailing_whitespaces_ignore_empty=false 38 | sp_cleanup.remove_unnecessary_casts=false 39 | sp_cleanup.remove_unnecessary_nls_tags=false 40 | sp_cleanup.remove_unused_imports=false 41 | sp_cleanup.remove_unused_local_variables=false 42 | sp_cleanup.remove_unused_private_fields=true 43 | sp_cleanup.remove_unused_private_members=false 44 | sp_cleanup.remove_unused_private_methods=true 45 | sp_cleanup.remove_unused_private_types=true 46 | sp_cleanup.sort_members=false 47 | sp_cleanup.sort_members_all=false 48 | sp_cleanup.use_blocks=false 49 | sp_cleanup.use_blocks_only_for_return_and_throw=false 50 | sp_cleanup.use_parentheses_in_expressions=false 51 | sp_cleanup.use_this_for_non_static_field_access=false 52 | sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true 53 | sp_cleanup.use_this_for_non_static_method_access=false 54 | sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 55 | -------------------------------------------------------------------------------- /github-site-plugin/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Aug 08 17:58:15 PDT 2011 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | resolveWorkspaceProjects=true 5 | version=1 6 | -------------------------------------------------------------------------------- /github-site-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.github.github 6 | github-maven-plugins-parent 7 | 0.13-SNAPSHOT 8 | 9 | 10 | site-maven-plugin 11 | maven-plugin 12 | GitHub Site Maven Plugin 13 | https://github.com/github/maven-plugins 14 | Maven plugin that commits files to a branch in a GitHub repository 15 | 16 | 17 | 0.9 18 | 19 | 20 | 21 | 22 | 23 | org.apache.maven.plugins 24 | maven-site-plugin 25 | 3.3 26 | 27 | true 28 | 29 | 30 | 31 | net.ju-n.maven.doxia 32 | doxia-module-markdown 33 | 1.0.0 34 | 35 | 36 | 37 | 38 | com.github.github 39 | site-maven-plugin 40 | ${last.released.version} 41 | 42 | Generated site for ${project.artifactId} ${project.version} 43 | site-plugin 44 | true 45 | 46 | 47 | 48 | 49 | site 50 | 51 | site-deploy 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-plugin-plugin 59 | 3.0 60 | 61 | 62 | generated-helpmojo 63 | 64 | helpmojo 65 | 66 | 67 | 68 | ghSite 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | com.github.github 79 | github-maven-core 80 | ${project.version} 81 | 82 | 83 | 84 | org.codehaus.plexus 85 | plexus-utils 86 | 3.0.1 87 | 88 | 89 | 90 | 91 | 92 | 93 | maven-plugin-plugin 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-jxr-plugin 98 | 2.3 99 | 100 | 101 | org.apache.maven.plugins 102 | maven-pmd-plugin 103 | 2.6 104 | 105 | true 106 | ${project.build.sourceEncoding} 107 | 100 108 | 1.5 109 | 110 | 111 | 112 | org.apache.maven.plugins 113 | maven-project-info-reports-plugin 114 | 2.6 115 | 116 | false 117 | false 118 | 119 | 120 | 121 | org.apache.maven.plugins 122 | maven-javadoc-plugin 123 | 2.8 124 | 125 | true 126 | 127 | http://download.oracle.com/javase/1.5.0/docs/api/ 128 | 129 | 130 | 131 | 132 | org.apache.maven.plugins 133 | maven-surefire-report-plugin 134 | 2.10 135 | 136 | 137 | org.codehaus.mojo 138 | jdepend-maven-plugin 139 | 2.0-beta-2 140 | 141 | 142 | org.apache.maven.plugins 143 | maven-changes-plugin 144 | 2.9 145 | 146 | https 147 | 443 148 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /github-site-plugin/src/main/java/com/github/maven/plugins/site/SiteMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 GitHub Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | package com.github.maven.plugins.site; 23 | 24 | import static java.lang.Integer.MAX_VALUE; 25 | import static org.eclipse.egit.github.core.Blob.ENCODING_BASE64; 26 | import static org.eclipse.egit.github.core.TreeEntry.MODE_BLOB; 27 | import static org.eclipse.egit.github.core.TreeEntry.TYPE_BLOB; 28 | import static org.eclipse.egit.github.core.TypedResource.TYPE_COMMIT; 29 | 30 | import com.github.maven.plugins.core.GitHubProjectMojo; 31 | import com.github.maven.plugins.core.PathUtils; 32 | import com.github.maven.plugins.core.StringUtils; 33 | 34 | import java.io.ByteArrayOutputStream; 35 | import java.io.File; 36 | import java.io.FileInputStream; 37 | import java.io.IOException; 38 | import java.text.MessageFormat; 39 | import java.util.ArrayList; 40 | import java.util.Arrays; 41 | import java.util.Collections; 42 | import java.util.GregorianCalendar; 43 | import java.util.List; 44 | 45 | import org.apache.maven.execution.MavenSession; 46 | import org.apache.maven.plugin.MojoExecutionException; 47 | import org.apache.maven.project.MavenProject; 48 | import org.apache.maven.settings.Settings; 49 | import org.eclipse.egit.github.core.Blob; 50 | import org.eclipse.egit.github.core.Commit; 51 | import org.eclipse.egit.github.core.CommitUser; 52 | import org.eclipse.egit.github.core.Reference; 53 | import org.eclipse.egit.github.core.RepositoryId; 54 | import org.eclipse.egit.github.core.Tree; 55 | import org.eclipse.egit.github.core.TreeEntry; 56 | import org.eclipse.egit.github.core.TypedResource; 57 | import org.eclipse.egit.github.core.User; 58 | import org.eclipse.egit.github.core.client.RequestException; 59 | import org.eclipse.egit.github.core.service.DataService; 60 | import org.eclipse.egit.github.core.service.UserService; 61 | import org.eclipse.egit.github.core.util.EncodingUtils; 62 | 63 | /** 64 | * Mojo which copies files to a GitHub repository branch. This directly uses the 65 | * GitHub data API to upload blobs, make commits, and update references and so a 66 | * local Git repository is not used. 67 | * 68 | * @author Kevin Sawicki (kevin@github.com) 69 | * @goal site 70 | */ 71 | public class SiteMojo extends GitHubProjectMojo { 72 | 73 | /** 74 | * BRANCH_DEFAULT 75 | */ 76 | public static final String BRANCH_DEFAULT = "refs/heads/gh-pages"; 77 | 78 | /** 79 | * NO_JEKYLL_FILE 80 | */ 81 | public static final String NO_JEKYLL_FILE = ".nojekyll"; 82 | 83 | /** 84 | * Branch to update 85 | * 86 | * @parameter default-value="refs/heads/gh-pages" 87 | */ 88 | private String branch = BRANCH_DEFAULT; 89 | 90 | /** 91 | * Path of tree 92 | * 93 | * @parameter 94 | */ 95 | private String path; 96 | 97 | /** 98 | * The commit message used when committing the site. 99 | * 100 | * @parameter 101 | * @required 102 | */ 103 | private String message; 104 | 105 | /** 106 | * The name of the repository. This setting must be set if the project's url and scm metadata are not set. 107 | * 108 | * @parameter expression="${github.site.repositoryName}" 109 | */ 110 | private String repositoryName; 111 | 112 | /** 113 | * The owner of repository. This setting must be set if the project's url and scm metadata are not set. 114 | * 115 | * @parameter expression="${github.site.repositoryOwner}" 116 | */ 117 | private String repositoryOwner; 118 | 119 | /** 120 | * The user name for authentication 121 | * 122 | * @parameter expression="${github.site.userName}" 123 | * default-value="${github.global.userName}" 124 | */ 125 | private String userName; 126 | 127 | /** 128 | * The password for authentication 129 | * 130 | * @parameter expression="${github.site.password}" 131 | * default-value="${github.global.password}" 132 | */ 133 | private String password; 134 | 135 | /** 136 | * The oauth2 token for authentication 137 | * 138 | * @parameter expression="${github.site.oauth2Token}" 139 | * default-value="${github.global.oauth2Token}" 140 | */ 141 | private String oauth2Token; 142 | 143 | /** 144 | * The Host for API calls. 145 | * 146 | * @parameter expression="${github.site.host}" 147 | * default-value="${github.global.host}" 148 | */ 149 | private String host; 150 | 151 | /** 152 | * The id of the server to use to retrieve the Github credentials. This id must identify a 153 | * server from your setting.xml file. 154 | * 155 | * @parameter expression="${github.site.server}" 156 | * default-value="${github.global.server}" 157 | */ 158 | private String server; 159 | 160 | /** 161 | * Paths and patterns to include 162 | * 163 | * @parameter 164 | */ 165 | private String[] includes; 166 | 167 | /** 168 | * Paths and patterns to exclude 169 | * 170 | * @parameter 171 | */ 172 | private String[] excludes; 173 | 174 | /** 175 | * The base directory to commit files from. target/site by default. 176 | * 177 | * @parameter expression="${siteOutputDirectory}" 178 | * default-value="${project.reporting.outputDirectory}" 179 | * @required 180 | */ 181 | private File outputDirectory; 182 | 183 | /** 184 | * The project being built 185 | * 186 | * @parameter expression="${project} 187 | * @required 188 | */ 189 | private MavenProject project; 190 | 191 | /** 192 | * The Maven session 193 | * 194 | * @parameter expression="${session} 195 | */ 196 | private MavenSession session; 197 | 198 | /** 199 | * The Maven settings 200 | * 201 | * @parameter expression="${settings} 202 | */ 203 | private Settings settings; 204 | 205 | /** 206 | * Force reference update 207 | * 208 | * @parameter expression="${github.site.force}" 209 | */ 210 | private boolean force; 211 | 212 | /** 213 | * Set it to {@code true} to always create a '.nojekyll' file at the root of the site if one 214 | * doesn't already exist. 215 | * 216 | * @parameter expression="${github.site.noJekyll}" 217 | */ 218 | private boolean noJekyll; 219 | 220 | /** 221 | * Set it to {@code true} to merge with existing the existing tree that is referenced by the commit 222 | * that the ref currently points to 223 | * 224 | * @parameter expression="${github.site.merge}" 225 | */ 226 | private boolean merge; 227 | 228 | /** 229 | * Show what blob, trees, commits, and references would be created/updated 230 | * but don't actually perform any operations on the target GitHub 231 | * repository. 232 | * 233 | * @parameter expression="${github.site.dryRun}" 234 | */ 235 | private boolean dryRun; 236 | 237 | /** 238 | * Skip the site upload. 239 | * 240 | * @parameter expression="${github.site.skip}" 241 | * default-value="false" 242 | * @since 0.9 243 | */ 244 | private boolean skip; 245 | 246 | /** 247 | * Create blob 248 | * 249 | * @param service 250 | * @param repository 251 | * @param path 252 | * @return blob SHA-1 253 | * @throws MojoExecutionException 254 | */ 255 | protected String createBlob(DataService service, RepositoryId repository, 256 | String path) throws MojoExecutionException { 257 | File file = new File(outputDirectory, path); 258 | final long length = file.length(); 259 | final int size = length > MAX_VALUE ? MAX_VALUE : (int) length; 260 | ByteArrayOutputStream output = new ByteArrayOutputStream(size); 261 | FileInputStream stream = null; 262 | try { 263 | stream = new FileInputStream(file); 264 | final byte[] buffer = new byte[8192]; 265 | int read; 266 | while ((read = stream.read(buffer)) != -1) 267 | output.write(buffer, 0, read); 268 | } catch (IOException e) { 269 | throw new MojoExecutionException("Error reading file: " 270 | + getExceptionMessage(e), e); 271 | } finally { 272 | if (stream != null) 273 | try { 274 | stream.close(); 275 | } catch (IOException e) { 276 | debug("Exception closing stream", e); 277 | } 278 | } 279 | 280 | Blob blob = new Blob().setEncoding(ENCODING_BASE64); 281 | String encoded = EncodingUtils.toBase64(output.toByteArray()); 282 | blob.setContent(encoded); 283 | 284 | try { 285 | if (isDebug()) 286 | debug(MessageFormat.format("Creating blob from {0}", 287 | file.getAbsolutePath())); 288 | if (!dryRun) 289 | return service.createBlob(repository, blob); 290 | else 291 | return null; 292 | } catch (IOException e) { 293 | throw new MojoExecutionException("Error creating blob: " 294 | + getExceptionMessage(e), e); 295 | } 296 | } 297 | 298 | public void execute() throws MojoExecutionException { 299 | if (skip) { 300 | info("Github Site Plugin execution skipped"); 301 | return; 302 | } 303 | 304 | RepositoryId repository = getRepository(project, repositoryOwner, 305 | repositoryName); 306 | 307 | if (dryRun) 308 | info("Dry run mode, repository will not be modified"); 309 | 310 | // Find files to include 311 | String baseDir = outputDirectory.getAbsolutePath(); 312 | String[] includePaths = StringUtils.removeEmpties(includes); 313 | String[] excludePaths = StringUtils.removeEmpties(excludes); 314 | if (isDebug()) 315 | debug(MessageFormat.format( 316 | "Scanning {0} and including {1} and exluding {2}", baseDir, 317 | Arrays.toString(includePaths), 318 | Arrays.toString(excludePaths))); 319 | String[] paths = PathUtils.getMatchingPaths(includePaths, excludePaths, 320 | baseDir); 321 | 322 | if (paths.length != 1) 323 | info(MessageFormat.format("Creating {0} blobs", paths.length)); 324 | else 325 | info("Creating 1 blob"); 326 | if (isDebug()) 327 | debug(MessageFormat.format("Scanned files to include: {0}", 328 | Arrays.toString(paths))); 329 | 330 | DataService service = new DataService(createClient(host, userName, 331 | password, oauth2Token, server, settings, session)); 332 | 333 | // Write blobs and build tree entries 334 | List entries = new ArrayList(paths.length); 335 | String prefix = path; 336 | if (prefix == null) 337 | prefix = ""; 338 | if (prefix.length() > 0 && !prefix.endsWith("/")) 339 | prefix += "/"; 340 | 341 | // Convert separator to forward slash '/' 342 | if ('\\' == File.separatorChar) 343 | for (int i = 0; i < paths.length; i++) 344 | paths[i] = paths[i].replace('\\', '/'); 345 | 346 | boolean createNoJekyll = noJekyll; 347 | 348 | for (String path : paths) { 349 | TreeEntry entry = new TreeEntry(); 350 | entry.setPath(prefix + path); 351 | // Only create a .nojekyll file if it doesn't already exist 352 | if (createNoJekyll && NO_JEKYLL_FILE.equals(entry.getPath())) 353 | createNoJekyll = false; 354 | entry.setType(TYPE_BLOB); 355 | entry.setMode(MODE_BLOB); 356 | entry.setSha(createBlob(service, repository, path)); 357 | entries.add(entry); 358 | } 359 | 360 | if (createNoJekyll) { 361 | TreeEntry entry = new TreeEntry(); 362 | entry.setPath(NO_JEKYLL_FILE); 363 | entry.setType(TYPE_BLOB); 364 | entry.setMode(MODE_BLOB); 365 | 366 | if (isDebug()) 367 | debug("Creating empty .nojekyll blob at root of tree"); 368 | if (!dryRun) 369 | try { 370 | entry.setSha(service.createBlob(repository, new Blob() 371 | .setEncoding(ENCODING_BASE64).setContent(""))); 372 | } catch (IOException e) { 373 | throw new MojoExecutionException( 374 | "Error creating .nojekyll empty blob: " 375 | + getExceptionMessage(e), e); 376 | } 377 | entries.add(entry); 378 | } 379 | 380 | Reference ref = null; 381 | try { 382 | ref = service.getReference(repository, branch); 383 | } catch (RequestException e) { 384 | if (404 != e.getStatus()) 385 | throw new MojoExecutionException("Error getting reference: " 386 | + getExceptionMessage(e), e); 387 | } catch (IOException e) { 388 | throw new MojoExecutionException("Error getting reference: " 389 | + getExceptionMessage(e), e); 390 | } 391 | 392 | if (ref != null && !TYPE_COMMIT.equals(ref.getObject().getType())) 393 | throw new MojoExecutionException( 394 | MessageFormat 395 | .format("Existing ref {0} points to a {1} ({2}) instead of a commmit", 396 | ref.getRef(), ref.getObject().getType(), 397 | ref.getObject().getSha())); 398 | 399 | // Write tree 400 | Tree tree; 401 | try { 402 | int size = entries.size(); 403 | if (size != 1) 404 | info(MessageFormat.format( 405 | "Creating tree with {0} blob entries", size)); 406 | else 407 | info("Creating tree with 1 blob entry"); 408 | String baseTree = null; 409 | if (merge && ref != null) { 410 | Tree currentTree = service.getCommit(repository, 411 | ref.getObject().getSha()).getTree(); 412 | if (currentTree != null) 413 | baseTree = currentTree.getSha(); 414 | info(MessageFormat.format("Merging with tree {0}", baseTree)); 415 | } 416 | if (!dryRun) 417 | tree = service.createTree(repository, entries, baseTree); 418 | else 419 | tree = new Tree(); 420 | } catch (IOException e) { 421 | throw new MojoExecutionException("Error creating tree: " 422 | + getExceptionMessage(e), e); 423 | } 424 | 425 | // Build commit 426 | Commit commit = new Commit(); 427 | commit.setMessage(message); 428 | commit.setTree(tree); 429 | 430 | try { 431 | UserService userService = new UserService(service.getClient()); 432 | User user = userService.getUser(); 433 | 434 | CommitUser author = new CommitUser(); 435 | author.setName(user.getName()); 436 | author.setEmail(userService.getEmails().get(0)); 437 | author.setDate(new GregorianCalendar().getTime()); 438 | 439 | commit.setAuthor(author); 440 | commit.setCommitter(author); 441 | } catch (IOException e) { 442 | throw new MojoExecutionException("Error retrieving user info: " 443 | + getExceptionMessage(e), e); 444 | } 445 | 446 | // Set parent commit SHA-1 if reference exists 447 | if (ref != null) 448 | commit.setParents(Collections.singletonList(new Commit().setSha(ref 449 | .getObject().getSha()))); 450 | 451 | Commit created; 452 | try { 453 | if (!dryRun) 454 | created = service.createCommit(repository, commit); 455 | else 456 | created = new Commit(); 457 | info(MessageFormat.format("Creating commit with SHA-1: {0}", 458 | created.getSha())); 459 | } catch (IOException e) { 460 | throw new MojoExecutionException("Error creating commit: " 461 | + getExceptionMessage(e), e); 462 | } 463 | 464 | TypedResource object = new TypedResource(); 465 | object.setType(TYPE_COMMIT).setSha(created.getSha()); 466 | if (ref != null) { 467 | // Update existing reference 468 | ref.setObject(object); 469 | try { 470 | info(MessageFormat.format( 471 | "Updating reference {0} from {1} to {2}", branch, 472 | commit.getParents().get(0).getSha(), created.getSha())); 473 | if (!dryRun) 474 | service.editReference(repository, ref, force); 475 | } catch (IOException e) { 476 | throw new MojoExecutionException("Error editing reference: " 477 | + getExceptionMessage(e), e); 478 | } 479 | } else { 480 | // Create new reference 481 | ref = new Reference().setObject(object).setRef(branch); 482 | try { 483 | info(MessageFormat.format( 484 | "Creating reference {0} starting at commit {1}", 485 | branch, created.getSha())); 486 | if (!dryRun) 487 | service.createReference(repository, ref); 488 | } catch (IOException e) { 489 | throw new MojoExecutionException("Error creating reference: " 490 | + getExceptionMessage(e), e); 491 | } 492 | } 493 | } 494 | } 495 | -------------------------------------------------------------------------------- /github-site-plugin/src/site/markdown/authentication.md.vm: -------------------------------------------------------------------------------- 1 | Configuring the GitHub credentials 2 | ================================== 3 | 4 | To successfully push the site to GitHub, the plugin needs your GitHub credentials, or at least credentials that can 5 | push to the repository. 6 | 7 | There are several ways to configure the access: 8 | 9 | * from the Maven `settings.xml` file using a pair username - password 10 | * from the plugin configuration (not recommended) 11 | 12 | Using username/password or oauth 13 | --------------------------------- 14 | 15 | The easiest way to give access to your repository is to add a `server` in your _settings.xml_ with your username and 16 | password (or from any account that can push to the repository). 17 | 18 | In your `~/.m2/settings.xml` file, add a `server` entry as follows: 19 | 20 | 21 | github 22 | YOUR_USERNAME 23 | YOUR_PASSWORD 24 | 25 | 26 | Using oauth is quite similar. Once you have done all the preliminaries (see [GitHub OAuth support](http://developer 27 | .github.com/v3/oauth/)), add a `server` entry as follows: 28 | 29 | 30 | github 31 | OAUTH2TOKEN 32 | 33 | 34 | The server's id (_github_) is used in the plugin configuration: 35 | 36 | 37 | 38 | ${project.groupId} 39 | ${project.artifactId} 40 | ${project.version} 41 | 42 | 43 | 44 | site 45 | 46 | site-deploy 47 | 48 | 49 | github 50 | 51 | 52 | Building site for my project 53 | 54 | ${site.path} 55 | 56 | true 57 | 58 | 59 | 60 | 61 | 62 | There is another way to configure the server id, avoiding you to write in in the plugin configuration. Set the 63 | `github.global.server` property: 64 | 65 | 66 | github 67 | 68 | 69 | This snippet can be either in your pom file or in a profile from your `settings.xml`. 70 | 71 | Setting the username and password inside the plugin configuration 72 | ----------------------------------------------------------------- 73 | 74 | This way is **not recommended**. You can configure the authentication from the plugin configuration with the 75 | following parameters: 76 | 77 | * `userName` (requires the password) 78 | * `password` (requires the username) 79 | * `oauth2Token` (is sufficient) 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /github-site-plugin/src/site/markdown/index.md.vm: -------------------------------------------------------------------------------- 1 | Github-Site-Plugin 2 | =================== 3 | 4 | The _github site plugin_ let you upload Maven Site to Github Pages. By pushing the site generated by Maven to your 5 | Git repository, it allows you to always have an up to date configuration benefiting from the git traceability. 6 | 7 | The plugin commits files generated and updates a specific branch reference in a GitHub repository. This plugin can 8 | be used to deploy a Maven site to a `gh-pages` branch so that it can be served statically as a GitHub Project Page. 9 | 10 | The plugin has a [site](site-mojo.html) goal and is configured with a goal prefix of `ghSite. To use the plugin, 11 | read the [quickstart](quickstart.html) guide. 12 | 13 | The plugin is built on top of [API v3](http://developer.github.com/) through the 14 | [GitHub Java library](https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core). 15 | 16 | Released builds are available from [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Ccom.github.github). 17 | 18 | Maven Site 19 | ---------- 20 | 21 | Maven Site let you manage project documentation close to the code. It can also generate reports about your project 22 | such as dependencies, test results, license and so on. To generate your site check the [maven-site-plugin] 23 | (http://maven.apache.org/plugins/maven-site-plugin/) and the 24 | [site generation](http://books.sonatype.com/mvnref-book/reference/site-generation.html) chapter from the Maven Reference Guide. 25 | 26 | Github Page 27 | ----------- 28 | 29 | Github page is a very simple, but powerful, way to publish simple web site using Git. It's free and available to all 30 | Github repositories. Check the [Github page site](http://pages.github.com/) for more information. -------------------------------------------------------------------------------- /github-site-plugin/src/site/markdown/locations.md.vm: -------------------------------------------------------------------------------- 1 | Configure the site location 2 | =========================== 3 | 4 | Root location 5 | ------------- 6 | 7 | Let's say that your Github project is: 8 | 9 | https://github.com/owner/project 10 | 11 | Your associated Github page is: 12 | 13 | http://owner.github.io/project 14 | 15 | 16 | Configuring the destination directory 17 | ------------------------------------- 18 | 19 | The plugin can be configured to upload the site to a specific directory, using the `path` parameter: 20 | 21 | 22 | ${project.groupId} 23 | ${project.artifactId} 24 | ${project.version} 25 | 26 | Generated site for ${project.artifactId} ${project.version} 27 | 28 | 29 | site-plugin 30 | 31 | true 32 | 33 | 34 | 35 | 36 | site 37 | 38 | site-deploy 39 | 40 | 41 | 42 | 43 | As a consequence, your site is published on: 44 | 45 | http://owner.github.io/project/site-plugin 46 | 47 | By setting the `path` to `\${project.version}`, you can keep the older versions of the site available. 48 | 49 | 50 | Using profiles to configure the destination directory 51 | ----------------------------------------------------- 52 | 53 | By using Maven profile, you can change the site destination. For example, the snapshot version are deployed in 54 | `snapshot`, while the released version are deployed to `\${project.version}`. 55 | 56 | Configure the `path` parameter too `site.path`: 57 | 58 | 59 | ${project.groupId} 60 | ${project.artifactId} 61 | ${project.version} 62 | 63 | Generated site for ${project.artifactId} ${project.version} 64 | 65 | 66 | \${site.path} 67 | 68 | true 69 | 70 | 71 | 72 | 73 | site 74 | 75 | site-deploy 76 | 77 | 78 | 79 | 80 | Define the properties in your pom, with the default (snapshot) value: 81 | 82 | 83 | snapshot 84 | 85 | 86 | 87 | Configure the release profile as follows: 88 | 89 | 90 | 91 | release 92 | 93 | release 94 | 95 | 96 | 97 | 98 | Don't forget to configure the `maven-release-plugin` to enable the release profile when performing your release: 99 | 100 | 101 | maven-release-plugin 102 | 2.2.1 103 | 104 | true 105 | deploy site site-deploy 106 | 107 | 108 | -------------------------------------------------------------------------------- /github-site-plugin/src/site/markdown/phase.md.vm: -------------------------------------------------------------------------------- 1 | Choosing the right Maven Phase 2 | ============================== 3 | 4 | 5 | The plugin is not bound to a Maven phase by default, so you have to choose one. Generally we use either `site` or 6 | `site-deploy`. The `site` phase is used by Maven to compute the project reports, 7 | and generate the site. The `site-deploy` phase happens after the `site` phase and is responsible for the upload of the 8 | site. Even if the `site-deploy` phase makes more sense, it requires some extra-configuration. 9 | 10 | 11 | Using the site phase 12 | -------------------- 13 | 14 | To use the site phase, just configure the plugin as follows: 15 | 16 | 17 | ${project.groupId} 18 | ${project.artifactId} 19 | ${project.version} 20 | 21 | 22 | 23 | 24 | 25 | 26 | site 27 | 28 | 29 | site 30 | 31 | 32 | 33 | 34 | However be aware that any site generation, even to check the current state, triggers the site upload. 35 | 36 | Using the site-deploy phase 37 | --------------------------- 38 | 39 | Instead of the `site` phase, you can use the `site-deploy` phase: 40 | 41 | 42 | ${project.groupId} 43 | ${project.artifactId} 44 | ${project.version} 45 | 46 | 47 | 48 | 49 | 50 | 51 | site 52 | 53 | site-deploy 54 | 55 | 56 | 57 | 58 | However, the regular `maven-site-plugin` is also bound to the `site-deploy` phase, 59 | and triggers the regular site upload. If you are using the Github Site Plugin you probably don't want to use the 60 | traditional upload feature, and so you must disable it: 61 | 62 | 63 | org.apache.maven.plugins 64 | maven-site-plugin 65 | 3.3 66 | 67 | true 68 | 69 | 70 | 71 | With this configuration, you site is uploaded to Github in the `site-deploy` phase as expected and without 72 | conflicting with the regular `maven-site-plugin` behavior. -------------------------------------------------------------------------------- /github-site-plugin/src/site/markdown/project.md.vm: -------------------------------------------------------------------------------- 1 | Configuring the project, repository and branch 2 | ============================================== 3 | 4 | To publish the site, the plugin must be able to deduced the Github project on which the site is uploaded. There are 5 | several ways to instructs the plugin with this information: 6 | 7 | * using the project's url 8 | * from the project's SCM settings 9 | * from the plugin configuration 10 | 11 | Using the project's url 12 | ----------------------- 13 | 14 | This is probably the simplest way. In your `pom.xml` file, set the project's `` to the Github project page: 15 | 16 | https://github.com/nanoko-project/coffee-mill-maven-plugin 17 | 18 | Of course, this settings can be inherited. 19 | 20 | Using the project's SCM 21 | ----------------------- 22 | 23 | The project's SCM indicates the source repository hosting your project. The plugin tries to deduce the 24 | repository from the `url`, `connection` and `developerConnection` (in this order). 25 | 26 | 27 | https://github.com/nanoko-project/coffee-mill-maven-plugin 28 | scm:git:git@github.com:nanoko-project/coffee-mill-maven-plugin.git 29 | scm:git:git@github.com:nanoko-project/coffee-mill-maven-plugin.git 30 | 31 | 32 | As for the project's url, these settings can be inherited. 33 | 34 | Using plugin configuration 35 | -------------------------- 36 | 37 | The project's repository is identified by repository's owner and name. You can configure these settings directly in 38 | the plugin configuration: 39 | 40 | 41 | 42 | ${project.groupId} 43 | ${project.artifactId} 44 | ${project.version} 45 | 46 | 47 | 48 | site 49 | 50 | 51 | site-deploy 52 | 53 | 54 | coffee-mill-maven-plugin 55 | nanoko-project 56 | 57 | github 58 | 59 | 60 | Building site for my project 61 | 62 | ${site.path} 63 | 64 | true 65 | 66 | 67 | 68 | 69 | 70 | Configuring the branch 71 | ---------------------- 72 | 73 | You can change the branch on which the site is pushed. By default, it uses _gh-pages_, 74 | the branch use by Github to generate the Github Page. Configure the _branch_ parameter of the plugin to change the 75 | branch to update. -------------------------------------------------------------------------------- /github-site-plugin/src/site/markdown/quickstart.md.vm: -------------------------------------------------------------------------------- 1 | # Quickstart Guide 2 | 3 | 4 | ## Preliminaries 5 | 6 | * Your Maven project has a site generated in `target/site`, and this site is ready to be deployed. 7 | * Your project sources are hosted on a Github repository 8 | * You have the authorizations to `push` code to this repository. 9 | 10 | ## Configuring the plugin 11 | 12 | In your project's `pom` file, add ${project.artifact} in the plugin list. 13 | 14 | 15 | 16 | 17 | ${project.groupId} 18 | ${project.artifactId} 19 | ${project.version} 20 | 21 | 22 | 23 | site 24 | 25 | 26 | site-deploy 27 | 28 | 29 | 30 | github 31 | 32 | 33 | Building site for my project 34 | 35 | ${site.path} 36 | 37 | true 38 | 39 | 40 | 41 | 42 | 43 | 44 | To know more about plugin's configuration and parameters check the (mojo page)[TODO]. 45 | 46 | ## Configuring the project location 47 | 48 | It's also important to configure the project `url` to indicate the project's Github repository, such as in: 49 | 50 | 51 | https://github.com/nanoko-project/coffee-mill-maven-plugin 52 | 53 | 54 | There are other ways to indicate the Github project on which the site will be published. Check the (configure 55 | project)[configure-project] page. 56 | 57 | ## Configuring the credentials 58 | 59 | Now that the plugin is configured, and the project location is specified correctly, 60 | you need to provide your Github credentials. These credentials are used by Maven to push the site. 61 | 62 | Open your Maven settings (`~/.m2/settings.xml`) and add the following server configuration: 63 | 64 | 65 | 66 | 67 | github 68 | YOUR_GITHUB_USERNAME 69 | YOUR_PASSWORD 70 | 71 | 72 | 73 | # Executing the plugin 74 | 75 | If you choose the `site phase in the plugin configuration, the Maven site is generated and uploaded with: 76 | 77 | 78 | mvn clean site 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /github-site-plugin/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Github Site Plugin 7 | # 8 | 9 | 10 | 11 | org.apache.maven.skins 12 | maven-fluido-skin 13 | 1.3.0 14 | 15 | 16 | 17 | false 18 | true 19 | 20 | 21 | github/maven-plugins 22 | right 23 | black 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |

35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.github.github 6 | github-maven-plugins-parent 7 | 0.13-SNAPSHOT 8 | pom 9 | 10 | 11 | org.sonatype.oss 12 | oss-parent 13 | 7 14 | 15 | 16 | 17 | github-core 18 | github-site-plugin 19 | 20 | 21 | GitHub Maven Plugins 22 | GitHub Maven plugins 23 | https://github.com/github/maven-plugins 24 | 25 | 26 | https://github.com/github/maven-plugins/issues 27 | GitHub 28 | 29 | 30 | 31 | 32 | MIT License 33 | http://www.opensource.org/licenses/mit-license.php 34 | repo 35 | 36 | 37 | 38 | 39 | https://github.com/github/maven-plugins 40 | scm:git:git://github.com/github/maven-plugins.git 41 | scm:git:git@github.com:github/maven-plugins.git 42 | 43 | 44 | 45 | 46 | kevin@github.com 47 | Kevin Sawicki 48 | https://github.com/kevinsawicki 49 | kevinsawicki 50 | 51 | 52 | clement.escoffier@[NO SPAM]gmail.com 53 | Clement Escoffier 54 | cescoffier 55 | 56 | 57 | 58 | 59 | UTF-8 60 | 61 | 62 | 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-javadoc-plugin 67 | 2.8 68 | 69 | 70 | 71 | jar 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.apache.maven.plugin-tools 80 | maven-plugin-tools-javadoc 81 | 2.9 82 | 83 | 84 | 85 | 86 | 87 | org.apache.maven.plugins 88 | maven-source-plugin 89 | 2.1.2 90 | 91 | 92 | 93 | jar 94 | 95 | 96 | 97 | 98 | 99 | org.apache.maven.plugins 100 | maven-jar-plugin 101 | 2.3.2 102 | 103 | 104 | 105 | true 106 | true 107 | 108 | 109 | 110 | 111 | 112 | org.apache.maven.plugins 113 | maven-compiler-plugin 114 | 2.3.2 115 | 116 | 1.5 117 | 1.5 118 | 119 | 120 | 121 | org.apache.maven.plugins 122 | maven-site-plugin 123 | 3.3 124 | 125 | true 126 | 127 | 128 | 129 | net.ju-n.maven.doxia 130 | doxia-module-markdown 131 | 1.0.0 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | sign 141 | 142 | 143 | 144 | org.apache.maven.plugins 145 | maven-gpg-plugin 146 | 1.4 147 | 148 | 149 | sign-artifacts 150 | verify 151 | 152 | sign 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | org.apache.maven 165 | maven-plugin-api 166 | 3.1.0 167 | provided 168 | 169 | 170 | org.apache.maven 171 | maven-core 172 | 3.1.0 173 | provided 174 | 175 | 176 | 177 | org.eclipse.mylyn.github 178 | org.eclipse.egit.github.core 179 | 3.1.0.201310021548-r 180 | 181 | 182 | 183 | com.google.code.gson 184 | gson 185 | 2.2.2 186 | 187 | 188 | 189 | com.google.guava 190 | guava 191 | 192 | 14.0 193 | 194 | 195 | 196 | junit 197 | junit 198 | 4.11 199 | test 200 | 201 | 202 | org.easytesting 203 | fest-assert 204 | 1.4 205 | test 206 | 207 | 208 | org.mockito 209 | mockito-all 210 | 1.9.5 211 | test 212 | 213 | 214 | 215 | 216 | 217 | egit 218 | Eclipse egit 219 | https://repo.eclipse.org/content/repositories/egit-releases/ 220 | 221 | 222 | 223 | --------------------------------------------------------------------------------