@Test public void calculatePermutation() throws UnableToCompleteException { final AppcacheLinker linker = new AppcacheLinker(); final ArtifactSet artifacts1 = new ArtifactSet(); artifacts1.add( new PermutationArtifact( AppcacheLinker.class, new Permutation( "1" ) ) ); artifacts1.add( new StandardGeneratedResource( "myapp.devmode.js", new byte[ 0 ] ) ); artifacts1.add( new StandardGeneratedResource( "file1.txt", new byte[ 0 ] ) ); final TreeMap<String, String> configs2 = new TreeMap<>(); configs2.put( "user.agent", "ie9" ); configs2.put( "screen.size", "large" ); configs2.put( "geolocationSupport", "maybe" ); artifacts1.add( new SelectionInformation( "S2", 0, configs2 ) ); final TreeMap<String, String> configs3 = new TreeMap<>(); configs3.put( "user.agent", "ie9" ); configs3.put( "screen.size", "small" ); configs3.put( "geolocationSupport", "maybe" ); artifacts1.add( new SelectionInformation( "S2", 1, configs3 ) ); final LinkerContext linkerContext = mock( LinkerContext.class ); when( linkerContext.getModuleName() ).thenReturn( "myapp" ); final TreeSet<SelectionProperty> properties = new TreeSet<>( Comparator.comparing( SelectionProperty::getName ) ); properties.add( new TestSelectionProperty( "user.agent", false ) ); properties.add( new TestSelectionProperty( "screen.size", false ) ); properties.add( new TestSelectionProperty( "geolocationSupport", true ) ); when( linkerContext.getProperties() ).thenReturn( properties ); final Permutation permutation = linker.calculatePermutation( TreeLogger.NULL, linkerContext, artifacts1 ); assertEquals( permutation.getPermutationName(), "S2" ); final Set<String> files = permutation.getPermutationFiles(); assertEquals( files.size(), 1 ); assertTrue( files.contains( "myapp/file1.txt" ) ); final List<SelectionDescriptor> softPermutations = permutation.getSelectors(); assertEquals( softPermutations.size(), 2 ); final SelectionDescriptor s0 = softPermutations.get( 0 ); final List<BindingProperty> bp0 = s0.getBindingProperties(); final BindingProperty property01 = findProperty( "user.agent", bp0 ); assertNotNull( property01 ); assertEquals( property01.getValue(), "ie9" ); final BindingProperty property02 = findProperty( "screen.size", bp0 ); assertNotNull( property02 ); assertEquals( property02.getValue(), "large" ); final SelectionDescriptor s1 = softPermutations.get( 1 ); final List<BindingProperty> bp1 = s1.getBindingProperties(); final BindingProperty property11 = findProperty( "user.agent", bp1 ); assertNotNull( property11 ); assertEquals( property11.getValue(), "ie9" ); final BindingProperty property12 = findProperty( "screen.size", bp1 ); assertNotNull( property12 ); assertEquals( property12.getValue(), "small" ); }
@Nullable final Permutation calculatePermutation( @Nonnull final TreeLogger logger, @Nonnull final LinkerContext context, @Nonnull final ArtifactSet artifacts ) throws UnableToCompleteException { Permutation permutation = null; for ( final SelectionInformation result : artifacts.find( SelectionInformation.class ) ) { final String strongName = result.getStrongName(); if ( null != permutation && !permutation.getPermutationName().equals( strongName ) ) { throw new UnableToCompleteException(); } if ( null == permutation ) { permutation = new Permutation( strongName ); final Set<String> artifactsForCompilation = getArtifactsForCompilation( context, artifacts ); permutation.getPermutationFiles().addAll( artifactsForCompilation ); } final List<BindingProperty> list = new ArrayList<>(); for ( final SelectionProperty property : context.getProperties() ) { if ( !property.isDerived() ) { final String name = property.getName(); final String value = result.getPropMap().get( name ); if ( null != value ) { list.add( new BindingProperty( name, value ) ); } } } final SelectionDescriptor selection = new SelectionDescriptor( strongName, list ); final List<SelectionDescriptor> selectors = permutation.getSelectors(); if ( !selectors.contains( selection ) ) { selectors.add( selection ); } } if ( null != permutation ) { logger.log( Type.DEBUG, "Calculated Permutation: " + permutation.getPermutationName() + " Selectors: " + permutation.getSelectors() ); } return permutation; }
AppcacheLinker extends AbstractLinker { @Nullable final Permutation calculatePermutation( @Nonnull final TreeLogger logger, @Nonnull final LinkerContext context, @Nonnull final ArtifactSet artifacts ) throws UnableToCompleteException { Permutation permutation = null; for ( final SelectionInformation result : artifacts.find( SelectionInformation.class ) ) { final String strongName = result.getStrongName(); if ( null != permutation && !permutation.getPermutationName().equals( strongName ) ) { throw new UnableToCompleteException(); } if ( null == permutation ) { permutation = new Permutation( strongName ); final Set<String> artifactsForCompilation = getArtifactsForCompilation( context, artifacts ); permutation.getPermutationFiles().addAll( artifactsForCompilation ); } final List<BindingProperty> list = new ArrayList<>(); for ( final SelectionProperty property : context.getProperties() ) { if ( !property.isDerived() ) { final String name = property.getName(); final String value = result.getPropMap().get( name ); if ( null != value ) { list.add( new BindingProperty( name, value ) ); } } } final SelectionDescriptor selection = new SelectionDescriptor( strongName, list ); final List<SelectionDescriptor> selectors = permutation.getSelectors(); if ( !selectors.contains( selection ) ) { selectors.add( selection ); } } if ( null != permutation ) { logger.log( Type.DEBUG, "Calculated Permutation: " + permutation.getPermutationName() + " Selectors: " + permutation.getSelectors() ); } return permutation; } }
AppcacheLinker extends AbstractLinker { @Nullable final Permutation calculatePermutation( @Nonnull final TreeLogger logger, @Nonnull final LinkerContext context, @Nonnull final ArtifactSet artifacts ) throws UnableToCompleteException { Permutation permutation = null; for ( final SelectionInformation result : artifacts.find( SelectionInformation.class ) ) { final String strongName = result.getStrongName(); if ( null != permutation && !permutation.getPermutationName().equals( strongName ) ) { throw new UnableToCompleteException(); } if ( null == permutation ) { permutation = new Permutation( strongName ); final Set<String> artifactsForCompilation = getArtifactsForCompilation( context, artifacts ); permutation.getPermutationFiles().addAll( artifactsForCompilation ); } final List<BindingProperty> list = new ArrayList<>(); for ( final SelectionProperty property : context.getProperties() ) { if ( !property.isDerived() ) { final String name = property.getName(); final String value = result.getPropMap().get( name ); if ( null != value ) { list.add( new BindingProperty( name, value ) ); } } } final SelectionDescriptor selection = new SelectionDescriptor( strongName, list ); final List<SelectionDescriptor> selectors = permutation.getSelectors(); if ( !selectors.contains( selection ) ) { selectors.add( selection ); } } if ( null != permutation ) { logger.log( Type.DEBUG, "Calculated Permutation: " + permutation.getPermutationName() + " Selectors: " + permutation.getSelectors() ); } return permutation; }  }
AppcacheLinker extends AbstractLinker { @Nullable final Permutation calculatePermutation( @Nonnull final TreeLogger logger, @Nonnull final LinkerContext context, @Nonnull final ArtifactSet artifacts ) throws UnableToCompleteException { Permutation permutation = null; for ( final SelectionInformation result : artifacts.find( SelectionInformation.class ) ) { final String strongName = result.getStrongName(); if ( null != permutation && !permutation.getPermutationName().equals( strongName ) ) { throw new UnableToCompleteException(); } if ( null == permutation ) { permutation = new Permutation( strongName ); final Set<String> artifactsForCompilation = getArtifactsForCompilation( context, artifacts ); permutation.getPermutationFiles().addAll( artifactsForCompilation ); } final List<BindingProperty> list = new ArrayList<>(); for ( final SelectionProperty property : context.getProperties() ) { if ( !property.isDerived() ) { final String name = property.getName(); final String value = result.getPropMap().get( name ); if ( null != value ) { list.add( new BindingProperty( name, value ) ); } } } final SelectionDescriptor selection = new SelectionDescriptor( strongName, list ); final List<SelectionDescriptor> selectors = permutation.getSelectors(); if ( !selectors.contains( selection ) ) { selectors.add( selection ); } } if ( null != permutation ) { logger.log( Type.DEBUG, "Calculated Permutation: " + permutation.getPermutationName() + " Selectors: " + permutation.getSelectors() ); } return permutation; }  @Override String getDescription(); @Override ArtifactSet link( @Nonnull final TreeLogger logger,
                           @Nonnull final LinkerContext context,
                           @Nonnull final ArtifactSet artifacts,
                           final boolean onePermutation ); }
AppcacheLinker extends AbstractLinker { @Nullable final Permutation calculatePermutation( @Nonnull final TreeLogger logger, @Nonnull final LinkerContext context, @Nonnull final ArtifactSet artifacts ) throws UnableToCompleteException { Permutation permutation = null; for ( final SelectionInformation result : artifacts.find( SelectionInformation.class ) ) { final String strongName = result.getStrongName(); if ( null != permutation && !permutation.getPermutationName().equals( strongName ) ) { throw new UnableToCompleteException(); } if ( null == permutation ) { permutation = new Permutation( strongName ); final Set<String> artifactsForCompilation = getArtifactsForCompilation( context, artifacts ); permutation.getPermutationFiles().addAll( artifactsForCompilation ); } final List<BindingProperty> list = new ArrayList<>(); for ( final SelectionProperty property : context.getProperties() ) { if ( !property.isDerived() ) { final String name = property.getName(); final String value = result.getPropMap().get( name ); if ( null != value ) { list.add( new BindingProperty( name, value ) ); } } } final SelectionDescriptor selection = new SelectionDescriptor( strongName, list ); final List<SelectionDescriptor> selectors = permutation.getSelectors(); if ( !selectors.contains( selection ) ) { selectors.add( selection ); } } if ( null != permutation ) { logger.log( Type.DEBUG, "Calculated Permutation: " + permutation.getPermutationName() + " Selectors: " + permutation.getSelectors() ); } return permutation; }  @Override String getDescription(); @Override ArtifactSet link( @Nonnull final TreeLogger logger,
                           @Nonnull final LinkerContext context,
                           @Nonnull final ArtifactSet artifacts,
                           final boolean onePermutation );  }