Repository: maven Updated Branches: refs/heads/MNG-6056 5a72f9552 -> 7fdce687f
[MNG-6056] Implement Feature Toggle Module to handle Feature Toggles o Renamed all reference consistent. o If no real toggle is defined in enumeration also command line will printout only "no toggles defined". This makes it easy to remove all feature toggles without the need to remove the command line options which can being keept. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/2a8bafd9 Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/2a8bafd9 Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/2a8bafd9 Branch: refs/heads/MNG-6056 Commit: 2a8bafd9f7b6911dda1de282e52aca12cc2f828a Parents: 5a72f95 Author: Karl Heinz Marbaise <khmarba...@apache.org> Authored: Sun Jul 3 00:14:56 2016 +0200 Committer: Karl Heinz Marbaise <khmarba...@apache.org> Committed: Sun Jul 3 00:17:43 2016 +0200 ---------------------------------------------------------------------- .../apache/maven/graph/DefaultGraphBuilder.java | 6 +- .../java/org/apache/maven/cli/MavenCli.java | 58 ++++++++++++-------- .../maven/feature/AvailableFeatureToggles.java | 41 +++++++++++--- .../feature/DefaultSelectedFeaturesTest.java | 25 +++++---- 4 files changed, 82 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/2a8bafd9/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java index a41f6ba..4b03f02 100644 --- a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java @@ -80,9 +80,9 @@ public class DefaultGraphBuilder return dependencyGraph( session, session.getProjects(), false ); } - if (selectedFeatures.isToggleActive( AvailableFeatureToggles.MNG10000 )) { - logger.info( " -> Features MNG 10000 is activated." ); - } +// if (selectedFeatures.isToggleActive( AvailableFeatureToggles.MNG10000 )) { +// logger.info( " -> Features MNG 10000 is activated." ); +// } List<MavenProject> projects = session.getProjects(); http://git-wip-us.apache.org/repos/asf/maven/blob/2a8bafd9/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 9b5d24d..4cf777b 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -194,7 +194,7 @@ public class MavenCli private ProfileSelector profileSelector; @Requirement - private FeatureToggles selectedFeatures; + private FeatureToggles featureToggles; public MavenCli() { @@ -458,34 +458,44 @@ public class MavenCli if ( cliRequest.commandLine.hasOption( CLIManager.LIST_FEATURES ) ) { - AvailableFeatureToggles[] availableFeatures = AvailableFeatureToggles.values(); + AvailableFeatureToggles[] availableFeatures = AvailableFeatureToggles.getAvailableFeatureToggles(); - System.out.println( "" ); - System.out.println( "Currently existing feature toggles which you can enable:" ); - System.out.println( "" ); - System.out.println( "Issue Option Description" ); - System.out.println( "--------- -------- ----------------------------------------------------" ); - for ( AvailableFeatureToggles feature : availableFeatures ) + if ( availableFeatures.length > 0 ) { - String wrappedString = WordUtils.wrap( feature.getDescription(), 60 ); - List<String> splitToList = Splitter.on( System.lineSeparator() ).splitToList( wrappedString ); - for ( int i = 0; i < splitToList.size(); i++ ) + System.out.println( "" ); + System.out.println( "Currently existing feature toggles which you can enable:" ); + System.out.println( "" ); + System.out.println( "Issue Option Description" ); + System.out.println( "--------- -------- ----------------------------------------------------" ); + for ( AvailableFeatureToggles feature : availableFeatures ) { - if ( i == 0 ) + String wrappedString = WordUtils.wrap( feature.getDescription(), 60 ); + List<String> splitToList = Splitter.on( System.lineSeparator() ).splitToList( wrappedString ); + for ( int i = 0; i < splitToList.size(); i++ ) { - System.out.print( String.format( "%-9s %-8s", feature.getIssue(), feature.name() ) + " " ); - } - else - { - System.out.print( String.format( "%-9s %-8s", "", "" ) + " " ); + if ( i == 0 ) + { + System.out.print( String.format( "%-9s %-8s", feature.getIssue(), feature.name() ) + " " ); + } + else + { + System.out.print( String.format( "%-9s %-8s", "", "" ) + " " ); + } + System.out.println( splitToList.get( i ) ); } - System.out.println( splitToList.get( i ) ); } - } - System.out.println( "" ); - System.out.println( "If you like to know more about a particular issue please visit: issues.apache.org/jira/browse/[ISSUE]" ); - throw new ExitException( 0 ); + System.out.println( "" ); + System.out.println( "If you like to know more about a particular issue please visit: issues.apache.org/jira/browse/[ISSUE]" ); + throw new ExitException( 0 ); + } + else + { + System.out.println( "" ); + System.out.println( "There are not feature toggles available." ); + throw new ExitException( 0 ); + + } } } @@ -640,7 +650,7 @@ public class MavenCli //Explicitly startup lookup for the component, cause it's used during command line //parsing etc. - selectedFeatures = container.lookup( FeatureToggles.class ); + featureToggles = container.lookup( FeatureToggles.class ); eventSpyDispatcher = container.lookup( EventSpyDispatcher.class ); @@ -1673,7 +1683,7 @@ public class MavenCli } } - selectedFeatures.setActivatedFeatureToggles( activatedFeatures ); + featureToggles.setActivatedFeatureToggles( activatedFeatures ); } return request; http://git-wip-us.apache.org/repos/asf/maven/blob/2a8bafd9/maven-feature/src/main/java/org/apache/maven/feature/AvailableFeatureToggles.java ---------------------------------------------------------------------- diff --git a/maven-feature/src/main/java/org/apache/maven/feature/AvailableFeatureToggles.java b/maven-feature/src/main/java/org/apache/maven/feature/AvailableFeatureToggles.java index 1294e59..a0b0d83 100644 --- a/maven-feature/src/main/java/org/apache/maven/feature/AvailableFeatureToggles.java +++ b/maven-feature/src/main/java/org/apache/maven/feature/AvailableFeatureToggles.java @@ -1,5 +1,8 @@ package org.apache.maven.feature; +import java.util.Arrays; +import java.util.List; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -29,16 +32,22 @@ public enum AvailableFeatureToggles //FIXME: Only some examples given. Nothing which exists in reality. - MNG9991( "MNG-9991", "First Feature to be toggable via command line option. " - + "First Feature to be toggable via command line option." ), - MNG9992( "MNG-9992", "First Feature to be toggable via command line option. " - + "First Feature to be toggable via command line option. XX asdfa. asdf dsf." ), - MNG9993( "MNG-9993", "First Feature to be toggable via command line option. " - + "More text than you think." ), - MNG10000( "MNG-10000", "First Feature to be toggable via command line option. " - + "Here much more than you thing." ); +// MNG9991( "MNG-9991", "First Feature to be toggable via command line option. " +// + "First Feature to be toggable via command line option." ), +// MNG9992( "MNG-9992", "First Feature to be toggable via command line option. " +// + "First Feature to be toggable via command line option. XX asdfa. asdf dsf." ), +// MNG9993( "MNG-9993", "First Feature to be toggable via command line option. " +// + "More text than you think." ), +// MNG10000( "MNG-10000", "First Feature to be toggable via command line option. " +// + "Here much more than you thing." ), -// UNKNONW ("UNKNOWN", "The unknown feature."); + /** + * This is an feature toggle which will never being used nor does it exist. + * This is only to mark the end of feature toggles. Also used for unit tests. + * + * Keep it at the end. + */ + UNKNOWN ("UNKNOWN", "The unknown feature."); private String issue; @@ -50,6 +59,20 @@ public enum AvailableFeatureToggles this.description = description; } + public static AvailableFeatureToggles[] getAvailableFeatureToggles() { + List<AvailableFeatureToggles> asList = Arrays.asList( AvailableFeatureToggles.values()); + + AvailableFeatureToggles[] result = new AvailableFeatureToggles[asList.size() - 1]; + + for ( int i = 0; i < asList.size() - 1; i++ ) + { + if (asList.get( i ) != UNKNOWN) { + result[i] = asList.get( 0 ); + } + } + return result; + } + public String getDescription() { return this.description; http://git-wip-us.apache.org/repos/asf/maven/blob/2a8bafd9/maven-feature/src/test/java/org/apache/maven/feature/DefaultSelectedFeaturesTest.java ---------------------------------------------------------------------- diff --git a/maven-feature/src/test/java/org/apache/maven/feature/DefaultSelectedFeaturesTest.java b/maven-feature/src/test/java/org/apache/maven/feature/DefaultSelectedFeaturesTest.java index cef2f57..112bea4 100644 --- a/maven-feature/src/test/java/org/apache/maven/feature/DefaultSelectedFeaturesTest.java +++ b/maven-feature/src/test/java/org/apache/maven/feature/DefaultSelectedFeaturesTest.java @@ -32,7 +32,7 @@ public class DefaultSelectedFeaturesTest { @Test - public void getActiveFeaturesShouldNotReturnNull() + public void getActiveFeaturesShouldNotReturnNotNullAndSizeOfListZero() { DefaultFeatureToggles sf = new DefaultFeatureToggles(); assertNotNull( sf.getActiveFeatureToggles() ); @@ -40,19 +40,20 @@ public class DefaultSelectedFeaturesTest } @Test - public void isFeatureActiveShouldReturnFalse() + public void isToggleActiveShouldReturnFalseIfNoTogglesHadBeenActivatedAtAll() { DefaultFeatureToggles sf = new DefaultFeatureToggles(); - assertFalse( sf.isToggleActive( AvailableFeatureToggles.MNG10000 ) ); + assertFalse( sf.isToggleActive( AvailableFeatureToggles.UNKNOWN ) ); } - @Test - public void isFeatureActiveShouldReturnFalseIfNotTheCorrectFeatureIsActivated() - { - DefaultFeatureToggles sf = new DefaultFeatureToggles(); - - sf.setActivatedFeatureToggles( Arrays.asList( AvailableFeatureToggles.MNG9991, AvailableFeatureToggles.MNG9992 ) ); - assertFalse( sf.isToggleActive( AvailableFeatureToggles.MNG10000 ) ); - assertTrue( sf.isToggleActive( AvailableFeatureToggles.MNG9991 ) ); - } +// @Test +// public void isToggleActiveShouldReturnFalseIfNotTheCorrectFeatureIsActivated() +// { +// DefaultFeatureToggles sf = new DefaultFeatureToggles(); +// +// sf.setActivatedFeatureToggles( Arrays.asList( AvailableFeatureToggles.UNKNOWN ) ); +// assertFalse( sf.isToggleActive( AvailableFeatureToggles.MNG10000 ) ); +// assertTrue( sf.isToggleActive( AvailableFeatureToggles.UNKNOWN ) ); +// +// } }