/*
 * Copyright (C) 2012 Red Hat, Inc.
 *
 * 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 org.commonjava.maven.ext.core.state;

import org.commonjava.maven.ext.annotation.ConfigValue;

import java.util.Properties;

/**
 * Captures configuration relating to enforcing removal of use of ${project.version} from pom.
 */
public class ProjectVersionEnforcingState
    implements State
{
    /**
     * Property used to set the enforcement mode.
     */
    @ConfigValue( docIndex = "misc.html#projectversion-expression-replacement" )
    private static final String ENFORCE_PROJECT_VERSION = "enforceProjectVersion";

    static
    {
        State.activeByDefault.add( ProjectVersionEnforcingState.class );
    }

    // Default to on.
    private boolean mode = true;

    public ProjectVersionEnforcingState( final Properties userProps )
    {
        initialise( userProps );
    }

    public void initialise( Properties userProps )
    {
        final String value = userProps.getProperty( ENFORCE_PROJECT_VERSION );
        if ( value != null )
        {
            mode = Boolean.parseBoolean( value );
        }
        else
        {
            mode = true;
        }
    }

    /**
     * Enabled by default; may be disabled by enforce-project-version.
     *
     * @see #ENFORCE_PROJECT_VERSION
     * @see State#isEnabled()
     * @see EnforcingMode
     */
    @Override
    public boolean isEnabled()
    {
        return mode;
    }
}

@@ -1269,20 +1269,23 @@
 boolean 
-mode
+enabled
  = true;
@@ -1471,28 +1471,39 @@
     
-final String value =
+enabled = Boolean.parseBoolean(
  use
@@ -1549,168 +1549,21 @@
 SION
- );%0A        if ( value != null )%0A        %7B%0A            mode = Boolean.parseBoolean( val
+, %22tr
 ue
+%22
  )
-;%0A        %7D%0A        else%0A        %7B%0A            mode = true;%0A        %7D
+ );
 %0A   
@@ -1819,20 +1819,23 @@
  return 
-mode
+enabled
 ;%0A    %7D%0A

Simplify setting of enabled mode in ProjectVersionEnforcingState