| 
									
										
										
										
											2020-03-23 15:35:58 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * MIT License
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * Copyright (c) 2020-present Cloudogu GmbH and Contributors
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in all
 | 
					
						
							|  |  |  |  * copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  *
 | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
					
						
							|  |  |  |  * SOFTWARE.
 | 
					
						
							|  |  |  |  */
 | 
					
						
							| 
									
										
										
										
											2020-12-16 10:58:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-25 09:49:52 +02:00
										 |  |  | package sonia.scm.lifecycle.modules;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import com.google.inject.AbstractModule;
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:58:38 +02:00
										 |  |  | import com.google.inject.TypeLiteral;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | import com.google.inject.throwingproviders.ThrowingProviderBinder;
 | 
					
						
							|  |  |  | import org.slf4j.Logger;
 | 
					
						
							|  |  |  | import org.slf4j.LoggerFactory;
 | 
					
						
							| 
									
										
										
										
											2019-05-14 14:12:08 +02:00
										 |  |  | import sonia.scm.SCMContext;
 | 
					
						
							|  |  |  | import sonia.scm.SCMContextProvider;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | import sonia.scm.io.DefaultFileSystem;
 | 
					
						
							|  |  |  | import sonia.scm.io.FileSystem;
 | 
					
						
							| 
									
										
										
										
											2020-02-12 14:45:13 +01:00
										 |  |  | import sonia.scm.lifecycle.DefaultRestarter;
 | 
					
						
							|  |  |  | import sonia.scm.lifecycle.Restarter;
 | 
					
						
							| 
									
										
										
										
											2019-05-15 15:05:35 +02:00
										 |  |  | import sonia.scm.plugin.PluginLoader;
 | 
					
						
							| 
									
										
										
										
											2020-12-16 10:58:29 +01:00
										 |  |  | import sonia.scm.repository.EventDrivenRepositoryArchiveCheck;
 | 
					
						
							|  |  |  | import sonia.scm.repository.RepositoryArchivedCheck;
 | 
					
						
							| 
									
										
										
										
											2019-05-10 08:06:36 +02:00
										 |  |  | import sonia.scm.repository.RepositoryLocationResolver;
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:48:06 +02:00
										 |  |  | import sonia.scm.repository.xml.MetadataStore;
 | 
					
						
							| 
									
										
										
										
											2019-05-10 08:06:36 +02:00
										 |  |  | import sonia.scm.repository.xml.PathBasedRepositoryLocationResolver;
 | 
					
						
							| 
									
										
										
										
											2019-05-14 11:54:25 +02:00
										 |  |  | import sonia.scm.security.CipherHandler;
 | 
					
						
							|  |  |  | import sonia.scm.security.CipherUtil;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | import sonia.scm.security.DefaultKeyGenerator;
 | 
					
						
							|  |  |  | import sonia.scm.security.KeyGenerator;
 | 
					
						
							|  |  |  | import sonia.scm.store.BlobStoreFactory;
 | 
					
						
							|  |  |  | import sonia.scm.store.ConfigurationEntryStoreFactory;
 | 
					
						
							|  |  |  | import sonia.scm.store.ConfigurationStoreFactory;
 | 
					
						
							|  |  |  | import sonia.scm.store.DataStoreFactory;
 | 
					
						
							| 
									
										
										
										
											2019-07-01 14:17:32 +02:00
										 |  |  | import sonia.scm.store.DefaultBlobDirectoryAccess;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | import sonia.scm.store.FileBlobStoreFactory;
 | 
					
						
							| 
									
										
										
										
											2021-01-28 11:40:35 +01:00
										 |  |  | import sonia.scm.store.FileRepositoryUpdateIterator;
 | 
					
						
							|  |  |  | import sonia.scm.store.FileStoreUpdateStepUtilFactory;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
 | 
					
						
							|  |  |  | import sonia.scm.store.JAXBConfigurationStoreFactory;
 | 
					
						
							|  |  |  | import sonia.scm.store.JAXBDataStoreFactory;
 | 
					
						
							| 
									
										
										
										
											2019-06-21 14:35:57 +02:00
										 |  |  | import sonia.scm.store.JAXBPropertyFileAccess;
 | 
					
						
							| 
									
										
										
										
											2019-07-01 14:17:32 +02:00
										 |  |  | import sonia.scm.update.BlobDirectoryAccess;
 | 
					
						
							| 
									
										
										
										
											2019-06-21 14:35:57 +02:00
										 |  |  | import sonia.scm.update.PropertyFileAccess;
 | 
					
						
							| 
									
										
										
										
											2021-01-28 11:40:35 +01:00
										 |  |  | import sonia.scm.update.RepositoryUpdateIterator;
 | 
					
						
							|  |  |  | import sonia.scm.update.StoreUpdateStepUtilFactory;
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:48:06 +02:00
										 |  |  | import sonia.scm.update.UpdateStepRepositoryMetadataAccess;
 | 
					
						
							| 
									
										
										
										
											2019-06-20 16:12:16 +02:00
										 |  |  | import sonia.scm.update.V1PropertyDAO;
 | 
					
						
							|  |  |  | import sonia.scm.update.xml.XmlV1PropertyDAO;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:58:38 +02:00
										 |  |  | import java.nio.file.Path;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | public class BootstrapModule extends AbstractModule {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static final Logger LOG = LoggerFactory.getLogger(BootstrapModule.class);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private final ClassOverrides overrides;
 | 
					
						
							| 
									
										
										
										
											2019-05-15 15:05:35 +02:00
										 |  |  |   private final PluginLoader pluginLoader;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-25 09:49:52 +02:00
										 |  |  |   public BootstrapModule(PluginLoader pluginLoader) {
 | 
					
						
							| 
									
										
										
										
											2019-05-14 11:19:45 +02:00
										 |  |  |     this.overrides = ClassOverrides.findOverrides(pluginLoader.getUberClassLoader());
 | 
					
						
							| 
									
										
										
										
											2019-05-15 15:05:35 +02:00
										 |  |  |     this.pluginLoader = pluginLoader;
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @Override
 | 
					
						
							|  |  |  |   protected void configure() {
 | 
					
						
							|  |  |  |     install(ThrowingProviderBinder.forModule(this));
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SCMContextProvider context = SCMContext.getContext();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bind(SCMContextProvider.class).toInstance(context);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bind(KeyGenerator.class).to(DefaultKeyGenerator.class);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-10 08:06:36 +02:00
										 |  |  |     bind(RepositoryLocationResolver.class).to(PathBasedRepositoryLocationResolver.class);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  |     bind(FileSystem.class, DefaultFileSystem.class);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-12 14:45:13 +01:00
										 |  |  |     bind(Restarter.class, DefaultRestarter.class);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 11:54:25 +02:00
										 |  |  |     // note CipherUtil uses an other generator
 | 
					
						
							|  |  |  |     bind(CipherHandler.class).toInstance(CipherUtil.getInstance().getCipherHandler());
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // bind core
 | 
					
						
							| 
									
										
										
										
											2020-12-16 10:58:29 +01:00
										 |  |  |     bind(RepositoryArchivedCheck.class, EventDrivenRepositoryArchiveCheck.class);
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  |     bind(ConfigurationStoreFactory.class, JAXBConfigurationStoreFactory.class);
 | 
					
						
							|  |  |  |     bind(ConfigurationEntryStoreFactory.class, JAXBConfigurationEntryStoreFactory.class);
 | 
					
						
							|  |  |  |     bind(DataStoreFactory.class, JAXBDataStoreFactory.class);
 | 
					
						
							|  |  |  |     bind(BlobStoreFactory.class, FileBlobStoreFactory.class);
 | 
					
						
							| 
									
										
										
										
											2019-05-15 15:05:35 +02:00
										 |  |  |     bind(PluginLoader.class).toInstance(pluginLoader);
 | 
					
						
							| 
									
										
										
										
											2019-06-20 16:12:16 +02:00
										 |  |  |     bind(V1PropertyDAO.class, XmlV1PropertyDAO.class);
 | 
					
						
							| 
									
										
										
										
											2019-06-21 14:35:57 +02:00
										 |  |  |     bind(PropertyFileAccess.class, JAXBPropertyFileAccess.class);
 | 
					
						
							| 
									
										
										
										
											2019-07-01 14:17:32 +02:00
										 |  |  |     bind(BlobDirectoryAccess.class, DefaultBlobDirectoryAccess.class);
 | 
					
						
							| 
									
										
										
										
											2021-01-28 11:40:35 +01:00
										 |  |  |     bind(RepositoryUpdateIterator.class, FileRepositoryUpdateIterator.class);
 | 
					
						
							|  |  |  |     bind(StoreUpdateStepUtilFactory.class, FileStoreUpdateStepUtilFactory.class);
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:58:38 +02:00
										 |  |  |     bind(new TypeLiteral<UpdateStepRepositoryMetadataAccess<Path>>() {}).to(new TypeLiteral<MetadataStore>() {});
 | 
					
						
							| 
									
										
										
										
											2019-05-09 10:36:27 +02:00
										 |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private <T> void bind(Class<T> clazz, Class<? extends T> defaultImplementation) {
 | 
					
						
							|  |  |  |     Class<? extends T> implementation = find(clazz, defaultImplementation);
 | 
					
						
							|  |  |  |     LOG.debug("bind {} to {}", clazz, implementation);
 | 
					
						
							|  |  |  |     bind(clazz).to(implementation);
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private <T> Class<? extends T> find(Class<T> clazz, Class<? extends T> defaultImplementation) {
 | 
					
						
							|  |  |  |     Class<? extends T> implementation = overrides.getOverride(clazz);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (implementation != null) {
 | 
					
						
							|  |  |  |       LOG.info("found override {} for {}", implementation, clazz);
 | 
					
						
							|  |  |  |     } else {
 | 
					
						
							|  |  |  |       implementation = defaultImplementation;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       LOG.trace(
 | 
					
						
							|  |  |  |         "no override available for {}, using default implementation {}",
 | 
					
						
							|  |  |  |         clazz, implementation);
 | 
					
						
							|  |  |  |     }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return implementation;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | }
 |