Coverage Report - org.apache.creadur.whisker.app.analysis.ResourceSourceAuditor
 
Classes in this File Line Coverage Branch Coverage Complexity
ResourceSourceAuditor
0%
0/22
0%
0/8
1.714
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  *  to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  *  with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License. 
 18  
  */
 19  
 package org.apache.creadur.whisker.app.analysis;
 20  
 
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collection;
 23  
 import java.util.TreeSet;
 24  
 
 25  
 import org.apache.commons.lang3.tuple.ImmutablePair;
 26  
 import org.apache.commons.lang3.tuple.Pair;
 27  
 import org.apache.creadur.whisker.model.Resource;
 28  
 import org.apache.creadur.whisker.model.Visitor;
 29  
 import org.apache.creadur.whisker.model.WithLicense;
 30  
 import org.apache.creadur.whisker.model.WithinDirectory;
 31  
 
 32  
 /**
 33  
  * 
 34  
  */
 35  0
 public class ResourceSourceAuditor extends Visitor {
 36  
 
 37  
     private WithLicense lastLicense;
 38  
     private WithinDirectory lastDirectory;
 39  
     
 40  0
     private final Collection<Pair<WithinDirectory, Resource>> resourcesMissingSource 
 41  
         = new TreeSet<Pair<WithinDirectory, Resource>>();
 42  
     
 43  0
     private final Collection<Pair<WithinDirectory, Resource>> resourcesWithSource 
 44  
     = new TreeSet<Pair<WithinDirectory, Resource>>();
 45  
     
 46  
     /**
 47  
      * @see Visitor#traversePublicDomain()
 48  
      */
 49  
     @Override
 50  
     public boolean traversePublicDomain() {
 51  
         // TODO: no need to traverse public domain 
 52  
         // TODO: think about API 
 53  0
         return false;
 54  
     }
 55  
 
 56  
     
 57  
     /**
 58  
      * @return the resourcesWithSource
 59  
      */
 60  
     public Collection<Pair<WithinDirectory, Resource>> getResourcesWithSource() {
 61  0
         return resourcesWithSource;
 62  
     }
 63  
 
 64  
     /**
 65  
      * @return the resourcesMissingSource
 66  
      */
 67  
     public Collection<Pair<WithinDirectory, Resource>> getResourcesMissingSource() {
 68  0
         return resourcesMissingSource;
 69  
     }
 70  
 
 71  
     /**
 72  
      * @see Visitor#visit(WithinDirectory)
 73  
      */
 74  
     @Override
 75  
     public void visit(WithinDirectory directory) {
 76  0
         this.lastDirectory = directory;
 77  0
     }
 78  
 
 79  
 
 80  
 
 81  
     /**
 82  
      * @see Visitor#visit(WithLicense)
 83  
      */
 84  
     @Override
 85  
     public void visit(WithLicense license) {
 86  0
         this.lastLicense = license;
 87  0
     }
 88  
 
 89  
     /**
 90  
      * @see Visitor#visit(Resource)
 91  
      */
 92  
     @Override
 93  
     public void visit(Resource resource) {
 94  0
         if (lastLicense == null) {
 95  0
             throw new IllegalArgumentException("Last license unexpectedly null for resource " + resource);
 96  0
         } else if (lastLicense.isSourceRequired()) {
 97  
             // TODO: Consider using ResourceDescription
 98  0
             final ImmutablePair<WithinDirectory, Resource> pair = new ImmutablePair<WithinDirectory, Resource>(lastDirectory, resource);
 99  0
             if (resource.hasSource()) {
 100  0
                 resourcesWithSource.add(pair);
 101  
             } else {
 102  0
                 resourcesMissingSource.add(pair);
 103  
             }
 104  
         } else {
 105  
             // Source not required
 106  
         }
 107  0
     }
 108  
 
 109  
 
 110  
     /**
 111  
      * @return
 112  
      */
 113  
     public Collection<Resource> getResourcesRequiringSourceLinks() {
 114  0
         final Collection<Resource> results = new ArrayList<Resource>();
 115  0
         for (Pair<WithinDirectory, Resource> pair: resourcesWithSource) {
 116  0
             results.add(pair.getRight());
 117  
         }
 118  0
         return results;
 119  
     }
 120  
     
 121  
 }