/**
 *
 * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved.
 *
 * Licensed 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 com.speedment.runtime.core.internal.component;

import com.speedment.common.injector.annotation.ExecuteBefore;
import com.speedment.common.injector.annotation.WithState;
import com.speedment.common.logger.Logger;
import com.speedment.common.logger.LoggerManager;
import com.speedment.runtime.config.Project;
import com.speedment.runtime.core.ApplicationMetadata;
import com.speedment.runtime.core.component.InfoComponent;
import com.speedment.runtime.core.component.ProjectComponent;

import static com.speedment.common.injector.State.INITIALIZED;
import static com.speedment.common.injector.State.STARTED;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

/**
 * The default implementation of the {@link ProjectComponent}-interface.
 * 
 * @author  Emil Forslund
 * @since   2.0.0
 */
public final class ProjectComponentImpl implements ProjectComponent {

    private final static Logger LOGGER = LoggerManager.getLogger(ProjectComponentImpl.class);
    private Project project;
    
    @ExecuteBefore(INITIALIZED)
    void loadProjectFromMetadata(@WithState(INITIALIZED) ApplicationMetadata metadata) {
        project = metadata.makeProject();
    }

    @ExecuteBefore(STARTED)
    void checkSpeedmentVersion(InfoComponent info) {
        final String expected = info.getEditionAndVersionString();
        final String actual = project.getSpeedmentVersion().orElse(null);
        if (!expected.equals(actual)) {
            LOGGER.warn(format(
                "Code generated using '%s' and running with '%s'. Make sure " +
                "versions and editions match to avoid performance and " +
                "stability issues.", actual, expected));
        }
    }

    @Override
    public Project getProject() {
        requireNonNull(project, 
            "Metadata has not yet been loaded! This is probably due to an " + 
            "incorrect initialization order."
        );
        
        return project;
    }

    @Override
    public void setProject(Project project) {
        this.project = requireNonNull(project);
    }
}
@@ -676,24 +676,71 @@
 component;%0A%0A
+import com.speedment.common.injector.Injector;%0A
 import com.s
@@ -1453,17 +1453,16 @@
 face.%0A *
- 
 %0A * @aut
@@ -1465,17 +1465,16 @@
 @author 
- 
 Emil For
@@ -1489,18 +1489,16 @@
  @since 
-  
 2.0.0%0A *
@@ -1693,20 +1693,16 @@
 roject;%0A
-    
 %0A    @Ex
@@ -1929,25 +1929,84 @@
 n(In
-foComponent info)
+jector injector) %7B%0A        injector.get(InfoComponent.class).ifPresent(ic -%3E
  %7B%0A 
@@ -2004,32 +2004,36 @@
 ic -%3E %7B%0A        
+  
+  
 final String exp
@@ -2041,19 +2041,17 @@
 cted = i
-nfo
+c
 .getEdit
@@ -2073,32 +2073,36 @@
 ring();%0A        
+   
+ 
 final String act
@@ -2159,16 +2159,20 @@
         
+    
 if (!exp
@@ -2191,24 +2191,28 @@
 (actual)) %7B%0A
+    
             
@@ -2247,16 +2247,20 @@
         
+    
 %22Code ge
@@ -2312,19 +2312,22 @@
 e sure %22
- +%0A
+%0A     
         
@@ -2333,16 +2333,17 @@
         
++
  %22versio
@@ -2394,11 +2394,14 @@
 nd %22
- +%0A
+%0A     
     
@@ -2411,16 +2411,17 @@
         
++
  %22stabil
@@ -2462,17 +2462,42 @@
         
-%7D
+    %7D%0A        %7D%0A        );
 %0A    %7D%0A%0A
@@ -2575,17 +2575,16 @@
 project,
- 
 %0A       
@@ -2651,19 +2651,16 @@
  to an %22
- + 
 %0A       
@@ -2663,16 +2663,18 @@
         
+ +
  %22incorr
@@ -2711,24 +2711,16 @@
      );%0A
-        
 %0A       
@@ -2858,8 +2858,9 @@
 %0A    %7D%0A%7D
+%0A

Make version check optional, Fix #589