Enumerate licenses
git-svn-id: https://svn.apache.org/repos/asf/creadur/tentacles/trunk@1462905 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/creadur/tentacles/LicenseType.java b/src/main/java/org/apache/creadur/tentacles/LicenseType.java
new file mode 100644
index 0000000..0be26e8
--- /dev/null
+++ b/src/main/java/org/apache/creadur/tentacles/LicenseType.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 org.apache.creadur.tentacles;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public enum LicenseType {
+
+ ASL_2_0("asl-2.0"), CPL_1_0("cpl-1.0"), CDDL_1_0("cddl-1.0");
+
+ public static Map<String, String> loadLicensesFrom(
+ final TentaclesResources tentaclesResources) throws IOException {
+ final Map<String, String> licenses =
+ new ConcurrentHashMap<String, String>();
+ for (final LicenseType type : LicenseType.values()) {
+ type.putTextInto(licenses, tentaclesResources);
+ }
+ return licenses;
+ }
+
+ private final String resourceName;
+ private final String resourcePath;
+
+ private LicenseType(final String resourceName) {
+ this.resourceName = resourceName;
+ this.resourcePath = "licenses/" + getResourceName() + ".txt";
+ }
+
+ public String getResourceName() {
+ return this.resourceName;
+ }
+
+ public String getResourcePath() {
+ return this.resourcePath;
+ }
+
+ public String readText(final TentaclesResources tentaclesResources)
+ throws IOException {
+ return tentaclesResources.readText(getResourcePath()).trim();
+ }
+
+ public void putTextInto(final Map<String, String> licenseTextByName,
+ final TentaclesResources tentaclesResources) throws IOException {
+ licenseTextByName.put(getResourceName(), readText(tentaclesResources));
+ }
+}
diff --git a/src/main/java/org/apache/creadur/tentacles/Main.java b/src/main/java/org/apache/creadur/tentacles/Main.java
index ada6149..fab0e2f 100644
--- a/src/main/java/org/apache/creadur/tentacles/Main.java
+++ b/src/main/java/org/apache/creadur/tentacles/Main.java
@@ -16,6 +16,7 @@
*/
package org.apache.creadur.tentacles;
+import static org.apache.creadur.tentacles.LicenseType.loadLicensesFrom;
import static org.apache.creadur.tentacles.RepositoryType.HTTP;
import static org.apache.creadur.tentacles.RepositoryType.LOCAL_FILE_SYSTEM;
@@ -60,7 +61,7 @@
private final File repository;
private final File content;
private final Reports reports;
- private final Map<String, String> licenses = new HashMap<String, String>();
+ private final Map<String, String> licenses;
private final NexusClient client;
private final Configuration configuration;
@@ -109,14 +110,7 @@
this.tentaclesResources.copyTo("legal/style.css", new File(this.local,
"style.css"));
- licenses("asl-2.0");
- licenses("cpl-1.0");
- licenses("cddl-1.0");
- }
-
- private void licenses(final String name) throws IOException {
- final String path = "licenses/" + name + ".txt";
- this.licenses.put(name, this.tentaclesResources.readText(path).trim());
+ this.licenses = loadLicensesFrom(this.tentaclesResources);
}
public static void main(final String[] args) throws Exception {