1 /*
   2  * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  */
   5 
   6 package com.oracle.appbundlers.utils;
   7 
   8 import java.io.IOException;
   9 import java.util.Collections;
  10 import java.util.HashMap;
  11 import java.util.Map;
  12 
  13 /**
  14  * @author Ramesh BG
  15  *
  16  */
  17 public class SourceFactory implements Constants {
  18 
  19     private SourceFactory() {
  20 
  21     }
  22 
  23     /*
  24      * com.greetings module
  25      */
  26 
  27     public static Source get_com_greetings_module() throws IOException {
  28         return get_com_greetings_module(Collections.emptyMap(),
  29                 Collections.emptyMap(), null);
  30     }
  31 
  32     /*
  33      * com.greetings module
  34      */
  35 
  36     public static Source get_com_greetings_module(
  37             Map<String, String> templateToClassnameMap,
  38             Map<String, String> replacementsInSourceCode, String mainClassName)
  39                     throws IOException {
  40 
  41         String mainClassInternal = COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME;
  42 
  43         if (mainClassName != null) {
  44             mainClassInternal = mainClassName;
  45         }
  46 
  47         Map<String, String> templateToClassNameMapInternal = new HashMap<String, String>();
  48         templateToClassNameMapInternal.put(FXAPP_JAVA_TEMPLATE,
  49                 mainClassInternal);
  50         templateToClassNameMapInternal.putAll(templateToClassnameMap);
  51 
  52         Map<String, String> replacementsInSourceCodeInternal = new HashMap<String, String>();
  53         replacementsInSourceCodeInternal.put(PRINTLN_STATEMENT,
  54                 SYSTEM_OUT_PRINTLN);
  55         replacementsInSourceCodeInternal.put(APP_NAME_REPLACEMENT_STATEMENT,
  56                 APP1_NAME);
  57         replacementsInSourceCodeInternal.put(PASS_STRING_REPLACEMENT_STATEMENT,
  58                 PASS_1);
  59         replacementsInSourceCodeInternal.put(PACKAGE_NAME_STATEMENT,
  60                 COM_GREETINGS_MODULE_CUM_PACKAGE_NAME);
  61         replacementsInSourceCodeInternal.put(DEPENDENT_MODULE, "");
  62 
  63         replacementsInSourceCodeInternal.putAll(replacementsInSourceCode);
  64 
  65         return new Source(COM_GREETINGS_MODULE_CUM_PACKAGE_NAME,
  66                 COM_GREETINGS_MODULE_INFO_TEMPLATE,
  67                 templateToClassNameMapInternal, mainClassInternal,
  68                 COM_GREETINGS_JAR_NAME, replacementsInSourceCodeInternal, true);
  69     }
  70 
  71     /*
  72      * com.greetings module
  73      */
  74 
  75     public static Source get_com_greetings_module(
  76             Map<String, String> templateToClassnameMap,
  77             Map<String, String> replacementsInSourceCode) throws IOException {
  78         return get_com_greetings_module(templateToClassnameMap,
  79                 replacementsInSourceCode, null);
  80     }
  81 
  82     /*
  83      * @return TempSource com.greetings module depends on custom.util
  84      * com.greetings ---> custom.util
  85      */
  86     public static Source get_com_greetings_module_depends_on_custom_util_module()
  87             throws IOException {
  88         Map<String, String> replacementsInSourceCode = new HashMap<>();
  89         replacementsInSourceCode.put(DEPENDENT_MODULE, "requires custom.util;");
  90         replacementsInSourceCode.put(PRINTLN_STATEMENT,
  91                 CUSTOM_UTIL_PRINTLN_STATEMENT);
  92 
  93         return SourceFactory.get_com_greetings_module(Collections.emptyMap(),
  94                 replacementsInSourceCode);
  95     }
  96 
  97     /*
  98      * custom.util module
  99      */
 100     public static Source get_custom_util_module() throws IOException {
 101         Map<String, String> templateToClassNameMap = new HashMap<String, String>();
 102         templateToClassNameMap.put(CUSTOM_UTIL_JAVA_TEMPLATE,
 103                 CUSTOM_UTIL_CLASS_NAME);
 104 
 105         Map<String, String> replacementsInSourceCode = new HashMap<String, String>();
 106         replacementsInSourceCode.put(PRINTLN_STATEMENT,
 107                 CUSTOM_UTIL_PRINTLN_STATEMENT);
 108         replacementsInSourceCode.put(APP_NAME_REPLACEMENT_STATEMENT, APP1_NAME);
 109         replacementsInSourceCode.put(PASS_STRING_REPLACEMENT_STATEMENT, PASS_1);
 110         replacementsInSourceCode.put(PACKAGE_NAME_STATEMENT,
 111                 CUSTOM_UTIL_PACKAGE_STATEMENT);
 112         replacementsInSourceCode.put(CLASS_NAME_STATEMENT,
 113                 CUSTOM_UTIL_CLASS_SIMPLE_NAME);
 114 
 115         return new Source(CUSTOM_UTIL_MODULE_NAME,
 116                 CUSTOM_UTIL_MODULE_TEMPLATE_FILE_NAME, templateToClassNameMap,
 117                 CUSTOM_UTIL_CLASS_FULLY_QUALIFIED_NAME, CUSTOM_UTIL_MODULE_NAME,
 118                 replacementsInSourceCode);
 119     }
 120 
 121     /*
 122      * com.shape.serviceinterface module
 123      */
 124     public static Source get_com_shape_serviceinterface_module(
 125             Map<String, String> templateToClassNameMap,
 126             Map<String, String> replacementsInSourceCode,
 127             String mainClassFullName) throws IOException {
 128 
 129         String mainClassFullNameInternal = COM_SHAPE_SERVICEINTERFACE_SHAPE_CLASS_NAME;
 130         if (mainClassFullName != null) {
 131             mainClassFullNameInternal = mainClassFullName;
 132         }
 133         Map<String, String> templateToClassNameMapInternal = new HashMap<String, String>();
 134         templateToClassNameMapInternal.put(
 135                 COM_SHAPE_SERVICEINTERFACE_SHAPE_TEMPLATE,
 136                 COM_SHAPE_SERVICEINTERFACE_SHAPE_CLASS_NAME);
 137         templateToClassNameMapInternal.putAll(templateToClassNameMap);
 138 
 139         return new Source(COM_SHAPE_SERVICEINTERFACE_MODULE_NAME,
 140                 COM_SHAPE_SERVICEINTERFACE_MODULE_INFO_TEMPLATE,
 141                 templateToClassNameMapInternal, mainClassFullNameInternal,
 142                 COM_SHAPE_SERVICEINTERFACE_MODULE_NAME, Collections.emptyMap(),
 143                 true);
 144     }
 145 
 146     /*
 147      * com.shape.serviceinterface module Main Module
 148      */
 149     public static Source get_com_shape_serviceinterface_module()
 150             throws IOException {
 151         String mainClassFullNameInternal = COM_SHAPE_SERVICEINTERFACE_SHAPE_CLASS_NAME;
 152         Map<String, String> templateToClassNameMapInternal = new HashMap<String, String>();
 153         templateToClassNameMapInternal.put(
 154                 COM_SHAPE_SERVICEINTERFACE_SHAPE_TEMPLATE,
 155                 COM_SHAPE_SERVICEINTERFACE_SHAPE_CLASS_NAME);
 156 
 157         return new Source(COM_SHAPE_SERVICEINTERFACE_MODULE_NAME,
 158                 COM_SHAPE_SERVICEINTERFACE_MODULE_INFO_TEMPLATE,
 159                 templateToClassNameMapInternal, mainClassFullNameInternal,
 160                 COM_SHAPE_SERVICEINTERFACE_MODULE_NAME, Collections.emptyMap(),
 161                 true);
 162     }
 163 
 164     /*
 165      * com.shape.serviceprovider.circle module
 166      */
 167 
 168     public static Source get_com_shape_serviceprovider_circle_module()
 169             throws IOException {
 170         Map<String, String> templateToClassNameMapInternal = new HashMap<String, String>();
 171         templateToClassNameMapInternal.put(
 172                 COM_SHAPE_SERVICEPROVIDER_CIRCLE_TEMPLATE,
 173                 COM_SHAPE_SERVICEPROVIDER_CIRCLE_CLASSNAME);
 174 
 175         return new Source(COM_SHAPE_SERVICEPROVIDER_CIRCLE_MODULENAME,
 176                 COM_SHAPE_SERVICEPROVIDER_CIRCLE_MODULE_INFO_TEMPLATE,
 177                 templateToClassNameMapInternal,
 178                 COM_SHAPE_SERVICEPROVIDER_CIRCLE_CLASSNAME,
 179                 COM_SHAPE_SERVICEPROVIDER_CIRCLE_MODULENAME,
 180                 Collections.emptyMap());
 181     }
 182 
 183     /*
 184      * com.shape.serviceprovider.rectangle module
 185      */
 186 
 187     public static Source get_com_shape_serviceprovider_rectangle_module()
 188             throws IOException {
 189         Map<String, String> templateToClassNameMapInternal = new HashMap<String, String>();
 190         templateToClassNameMapInternal.put(
 191                 COM_SHAPE_SERVICEPROVIDER_RECTANGLE_TEMPLATE,
 192                 COM_SHAPE_SERVICEPROVIDER_RECTANGLE_CLASS_NAME);
 193 
 194         return new Source(COM_SHAPE_SERVICEPROVIDER_RECTANGLE_MODULE_NAME,
 195                 COM_SHAPE_SERVICEPROVIDER_RECTANGLE_MODULE_INFO_TEMPLATE,
 196                 templateToClassNameMapInternal,
 197                 COM_SHAPE_SERVICEPROVIDER_RECTANGLE_CLASS_NAME,
 198                 COM_SHAPE_SERVICEPROVIDER_RECTANGLE_MODULE_NAME,
 199                 Collections.emptyMap());
 200     }
 201 
 202     /*
 203      * com.shape.test module
 204      */
 205 
 206     public static Source get_com_shape_test_module() throws IOException {
 207         Map<String, String> templateToClassNameMapInternal = new HashMap<String, String>();
 208         templateToClassNameMapInternal.put(
 209                 COM_SHAPE_TEST_LIMITMODSMAINCLASS_TEMPLATE,
 210                 COM_SHAPE_TEST_LIMITMODSMAINCLASS);
 211 
 212         return new Source(COM_SHAPE_TEST_MODULE_NAME,
 213                 COM_SHAPE_TEST_MODULE_INFO_TEMPLATE,
 214                 templateToClassNameMapInternal,
 215                 COM_SHAPE_TEST_LIMITMODSMAINCLASS, COM_SHAPE_TEST_MODULE_NAME,
 216                 Collections.emptyMap());
 217     }
 218 
 219     /*
 220      * unnamed module com.greetings
 221      */
 222     public static Source get_com_greetings_app_unnamed_module()
 223             throws IOException {
 224         return get_com_greetings_app_unnamed_module(Collections.emptyMap());
 225     }
 226 
 227     /*
 228      * unnamed module com.greetings
 229      */
 230     public static Source get_com_greetings_app_unnamed_module(
 231             Map<String, String> replacementsInSourceCode) throws IOException {
 232 
 233         return get_com_greetings_app_unnamed_module(
 234                 COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
 235                 replacementsInSourceCode);
 236     }
 237 
 238     /*
 239      * unnamed module com.greetings
 240      */
 241     public static Source get_com_greetings_app_unnamed_module(String fullName,
 242             Map<String, String> replacementsInSourceCode) throws IOException {
 243 
 244         Map<String, String> replacementsInSourceCodeInternal = new HashMap<String, String>();
 245         replacementsInSourceCodeInternal.put(PRINTLN_STATEMENT,
 246                 SYSTEM_OUT_PRINTLN);
 247         replacementsInSourceCodeInternal.put(APP_NAME_REPLACEMENT_STATEMENT,
 248                 APP1_NAME);
 249         replacementsInSourceCodeInternal.put(PASS_STRING_REPLACEMENT_STATEMENT,
 250                 PASS_1);
 251         replacementsInSourceCodeInternal.put(PACKAGE_NAME_STATEMENT,
 252                 COM_GREETINGS_MODULE_CUM_PACKAGE_NAME);
 253         replacementsInSourceCodeInternal.putAll(replacementsInSourceCode);
 254 
 255         return new Source(fullName, FXAPP_JAVA_TEMPLATE,
 256                 COM_GREETINGS_MODULE_CUM_PACKAGE_NAME,
 257                 replacementsInSourceCodeInternal);
 258 
 259     }
 260 
 261     /*
 262      * testapp.util.Util unnamed module
 263      */
 264     public static Source get_test_app_util_unnamed_module() throws IOException {
 265         Map<String, String> replacementsInSourceCode = new HashMap<String, String>();
 266         replacementsInSourceCode.put(PRINTLN_STATEMENT,
 267                 CUSTOM_UTIL_PRINTLN_STATEMENT);
 268         replacementsInSourceCode.put(PACKAGE_NAME_STATEMENT,
 269                 CUSTOM_UTIL_UNNAMED_MODULE_PACKAGE_STATEMENT);
 270         replacementsInSourceCode.put(CLASS_NAME_STATEMENT,
 271                 CUSTOM_UTIL_CLASS_SIMPLE_NAME);
 272 
 273         return new Source(CUSTOM_UTIL_UNNAMED_MODULE_FULLY_QUALIFIED_CLASS_NAME,
 274                 CUSTOM_UTIL_JAVA_TEMPLATE, CUSTOM_UTIL_CLASS_SIMPLE_NAME,
 275                 replacementsInSourceCode);
 276     }
 277 
 278     /*
 279      * com.greetings unnamed module depends on testapp.util unnamed module
 280      */
 281     public static Source get_com_greetings_unnamed_module_depends_on_test_app_util_unnamed_module()
 282             throws IOException {
 283         Map<String, String> replacementsInSourceCode = new HashMap<String, String>();
 284         replacementsInSourceCode.put(PRINTLN_STATEMENT,
 285                 CUSTOM_UTIL_PRINTLN_STATEMENT);
 286 
 287         return SourceFactory
 288                 .get_com_greetings_app_unnamed_module(replacementsInSourceCode);
 289     }
 290 
 291     /*
 292      * com.greetings unnamed module depends on testapp.util unnamed module
 293      */
 294     public static Source get_com_greetings_unnamed_module_depends_on_testapp_util_unnamed_module(
 295             Map<String, String> replacementsInSourceCode) throws IOException {
 296         Map<String, String> replacementsInSourceCodeInternal = new HashMap<String, String>();
 297         replacementsInSourceCodeInternal.put(PRINTLN_STATEMENT,
 298                 CUSTOM_UTIL_PRINTLN_STATEMENT);
 299         replacementsInSourceCodeInternal.putAll(replacementsInSourceCode);
 300 
 301         return SourceFactory.get_com_greetings_app_unnamed_module(
 302                 replacementsInSourceCodeInternal);
 303     }
 304 }