[java-support] branch master updated: Add test utility class for generating project Git resource URLs.

Brent Putman putmanb at georgetown.edu
Mon Mar 20 21:31:31 EDT 2017


This is an automated email from the git hooks/post-receive script.

putmanb pushed a commit to branch master
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=f41e485cac8590a4f732475e61eef83645b595d1

The following commit(s) were added to refs/heads/master by this push:
       new  f41e485   Add test utility class for generating project Git resource URLs.
f41e485 is described below

commit f41e485cac8590a4f732475e61eef83645b595d1
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Mon Mar 20 21:31:10 2017 -0400

    Add test utility class for generating project Git resource URLs.
    
    This is in support of IDP-1146.
---
 .../java/support/repository/RepositorySupport.java | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/src/test/java/net/shibboleth/utilities/java/support/repository/RepositorySupport.java b/src/test/java/net/shibboleth/utilities/java/support/repository/RepositorySupport.java
new file mode 100644
index 0000000..da05fc1
--- /dev/null
+++ b/src/test/java/net/shibboleth/utilities/java/support/repository/RepositorySupport.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.utilities.java.support.repository;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/**
+ * Support class for working with the project version control repository.
+ */
+public final class RepositorySupport {
+    
+    /** Constructor. */
+    private RepositorySupport() { } 
+    
+    /**
+     * Build an HTTPS resource URL for the selected repository name and path.
+     * 
+     * @param repoName the repository name.  If Git, do not include the ".git" suffix.
+     * @param resourcePath The relative resource path within the repository, e.g. "foo/bar/baz/file.txt"
+     * @return the HTTPS resource URL
+     */
+    public static String buildHTTPSResourceURL(@Nonnull final String repoName, @Nonnull final String resourcePath) {
+        return buildHTTPResourceURL(repoName, resourcePath, true);
+    }
+    
+    /**
+     * Build an HTTP/HTTPS resource URL for the selected repository name and path.
+     * 
+     * @param repoName the repository name.  If Git, do not include a trailing ".git" suffix for bare repos.
+     * @param resourcePath The relative resource path within the repository, e.g. "foo/bar/baz/file.txt"
+     * @param https if true, use https if possible, otherwise use http
+     * @return the HTTP(S) resource URL
+     */
+    public static String buildHTTPResourceURL(@Nonnull final String repoName, @Nonnull final String resourcePath, 
+            final boolean https) {
+        
+        final String repo = Constraint.isNotNull(StringSupport.trimOrNull(repoName), 
+                "Repository name was null or empty");
+        String path = Constraint.isNotNull(StringSupport.trimOrNull(resourcePath), 
+                "Resource path was null or empty");
+        
+        if (path.startsWith("/")) {
+            path = path.substring(1);
+        }
+        
+        return String.format("%s://git.shibboleth.net/view/?p=%s.git&a=blob_plain&f=%s&hb=master", 
+                https ? "https" : "http", repo, path);
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list