|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * wcm.io |
| 4 | + * %% |
| 5 | + * Copyright (C) 2015 wcm.io |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package io.wcm.devops.maven.nodejsproxy.resource; |
| 21 | + |
| 22 | +import io.wcm.devops.maven.nodejsproxy.MavenProxyConfiguration; |
| 23 | + |
| 24 | +import org.apache.commons.lang3.StringUtils; |
| 25 | + |
| 26 | +/** |
| 27 | + * Builds HTML index page |
| 28 | + */ |
| 29 | +public final class IndexPageBuilder { |
| 30 | + |
| 31 | + private static final String[] EXAMPLE_URLS = new String[] { |
| 32 | + "${groupIdPath}/${nodeJsArtifactId}/0.12.0/${nodeJsArtifactId}-0.12.0.pom", |
| 33 | + "${groupIdPath}/${nodeJsArtifactId}/0.12.0/${nodeJsArtifactId}-0.12.0-windows-x86.exe", |
| 34 | + "${groupIdPath}/${nodeJsArtifactId}/0.12.0/${nodeJsArtifactId}-0.12.0-windows-x64.exe", |
| 35 | + "${groupIdPath}/${nodeJsArtifactId}/0.12.0/${nodeJsArtifactId}-0.12.0-linux-x86.tar.gz", |
| 36 | + "${groupIdPath}/${nodeJsArtifactId}/0.12.0/${nodeJsArtifactId}-0.12.0-linux-x64.tar.gz", |
| 37 | + "${groupIdPath}/${nodeJsArtifactId}/0.12.0/${nodeJsArtifactId}-0.12.0-darwin-x86.tar.gz", |
| 38 | + "${groupIdPath}/${nodeJsArtifactId}/0.12.0/${nodeJsArtifactId}-0.12.0-darwin-x64.tar.gz", |
| 39 | + "${groupIdPath}/${npmArtifactId}/1.4.9/${npmArtifactId}-1.4.9.pom", |
| 40 | + "${groupIdPath}/${npmArtifactId}/1.4.9/${npmArtifactId}-1.4.9.tgz" |
| 41 | + }; |
| 42 | + |
| 43 | + private IndexPageBuilder() { |
| 44 | + // static methods only |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Build HTML index page |
| 49 | + */ |
| 50 | + public static String build(MavenProxyConfiguration config) { |
| 51 | + StringBuilder exampleUrlsMarkup = new StringBuilder(); |
| 52 | + for (String exampleUrl : EXAMPLE_URLS) { |
| 53 | + String url = exampleUrl; |
| 54 | + url = StringUtils.replace(url, "${groupIdPath}", StringUtils.replace(config.getGroupId(), ".", "/")); |
| 55 | + url = StringUtils.replace(url, "${nodeJsArtifactId}", config.getNodeJsArtifactId()); |
| 56 | + url = StringUtils.replace(url, "${npmArtifactId}", config.getNpmArtifactId()); |
| 57 | + exampleUrlsMarkup.append("<li><a href=\"").append(url).append("\">").append(url).append("</a></li>"); |
| 58 | + |
| 59 | + } |
| 60 | + return "<html>" |
| 61 | + + "<head><title>Maven NodeJS Proxy</title></head>" |
| 62 | + + "<body>" |
| 63 | + + "<h1>Maven NodeJS Proxy</h1>" |
| 64 | + + "<p>This is a Maven Artifact Proxy for NodeJS binaries located at: " |
| 65 | + + "<a href=\"" + config.getNodeJsBinariesRootUrl() + "\">" + config.getNodeJsBinariesRootUrl() + "</a></p>" |
| 66 | + + "<p>Every call to this repository is routed directly to this URL.</p>" |
| 67 | + + "<p><strong>Please never use this Maven repository directly in your maven builds, but only via an Repository Manager " |
| 68 | + + "which caches the resolved artifacts.</strong></p>" |
| 69 | + + "<p>If you want to setup your own proxy get the source code:" |
| 70 | + + "<a href=\"https://github.com/wcm-io-devops/maven-nodejs-proxy\">https://github.com/wcm-io-devops/maven-nodejs-proxy</a></p>" |
| 71 | + + "<hr/>" |
| 72 | + + "<p>Examples:</p>" |
| 73 | + + "<ul>" |
| 74 | + + exampleUrlsMarkup |
| 75 | + + "</ul>" |
| 76 | + + "<p>For all files SHA1 checksums are supported (.sha1 suffix). MD5 checksums are not supported.</p>" |
| 77 | + + "</body>" |
| 78 | + + "</html>"; |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments