Inject templates

git-svn-id: https://svn.apache.org/repos/asf/creadur/tentacles/trunk@1462794 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/creadur/tentacles/Main.java b/src/main/java/org/apache/creadur/tentacles/Main.java
index d3b2e93..dfbda6b 100644
--- a/src/main/java/org/apache/creadur/tentacles/Main.java
+++ b/src/main/java/org/apache/creadur/tentacles/Main.java
@@ -65,6 +65,7 @@
     private final Configuration configuration;
     private final FileSystem fileSystem;
     private final IOSystem ioSystem;
+    private final Templates templates;
 
     public Main(final String... args) throws Exception {
         this(new Configuration(args), new FileSystem(), new IOSystem());
@@ -73,15 +74,17 @@
     public Main(final Configuration configuration, final FileSystem fileSystem,
             final IOSystem ioSystem) throws Exception {
         this(configuration, fileSystem, new NexusClient(fileSystem, ioSystem),
-                ioSystem);
+                ioSystem, new Templates(ioSystem));
     }
 
     public Main(final Configuration configuration, final FileSystem fileSystem,
-            final NexusClient client, final IOSystem ioSystem) throws Exception {
+            final NexusClient client, final IOSystem ioSystem,
+            final Templates templates) throws Exception {
         this.client = client;
         this.configuration = configuration;
         this.fileSystem = fileSystem;
         this.ioSystem = ioSystem;
+        this.templates = templates;
 
         this.local =
                 new File(this.configuration.getRootDirectoryForLocalOutput());
@@ -138,8 +141,8 @@
             archives.add(archive);
         }
 
-        Templates.template("legal/archives.vm", this.ioSystem)
-                .add("archives", archives).add("reports", this.reports)
+        this.templates.template("legal/archives.vm").add("archives", archives)
+                .add("reports", this.reports)
                 .write(new File(this.local, "archives.html"));
 
         reportLicenses(archives);
@@ -152,7 +155,7 @@
             throws IOException {
         initLicenses(archives);
 
-        Templates.template("legal/licenses.vm", this.ioSystem)
+        this.templates.template("legal/licenses.vm")
                 .add("licenses", getLicenses(archives))
                 .add("reports", this.reports)
                 .write(new File(this.local, "licenses.html"));
@@ -198,8 +201,8 @@
         }
         for (final Archive archive : archives) {
 
-            Templates
-                    .template("legal/archive-licenses.vm", this.ioSystem)
+            this.templates
+                    .template("legal/archive-licenses.vm")
                     .add("archive", archive)
                     .add("reports", this.reports)
                     .write(new File(this.local, this.reports.licenses(archive)));
@@ -277,7 +280,7 @@
                 }
             }
 
-            Templates.template("legal/archive-notices.vm", this.ioSystem)
+            this.templates.template("legal/archive-notices.vm")
                     .add("archive", archive).add("reports", this.reports)
                     .write(new File(this.local, this.reports.notices(archive)));
         }
@@ -305,7 +308,7 @@
             }
         }
 
-        Templates.template("legal/notices.vm", this.ioSystem)
+        this.templates.template("legal/notices.vm")
                 .add("notices", notices.values()).add("reports", this.reports)
                 .write(new File(this.local, "notices.html"));
     }
diff --git a/src/main/java/org/apache/creadur/tentacles/Templates.java b/src/main/java/org/apache/creadur/tentacles/Templates.java
index 200e0ae..32e0047 100644
--- a/src/main/java/org/apache/creadur/tentacles/Templates.java
+++ b/src/main/java/org/apache/creadur/tentacles/Templates.java
@@ -23,11 +23,11 @@
 
 public final class Templates {
 
-    private static final Templates INSTANCE = new Templates();
-
+    private final IOSystem ioSystem;
     private final VelocityEngine engine;
 
-    private Templates() {
+    public Templates(final IOSystem ioSystem) {
+        this.ioSystem = ioSystem;
         final Properties properties = new Properties();
         properties.setProperty("file.resource.loader.cache", "true");
         properties.setProperty("resource.loader", "file, class");
@@ -45,11 +45,7 @@
         this.engine.init(properties);
     }
 
-    public static TemplateBuilder template(final String name, final IOSystem ioSystem) {
-        return INSTANCE.builder(name, ioSystem);
-    }
-
-    private TemplateBuilder builder(final String name, final IOSystem ioSystem) {
-        return new TemplateBuilder(name, ioSystem, this.engine);
+    public TemplateBuilder template(final String name) {
+        return new TemplateBuilder(name, this.ioSystem, this.engine);
     }
 }