Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Red Hat, Inc. and/or its affiliates.
   *
   * Licensed under the Eclipse Public License version 1.0, available at
   * http://www.eclipse.org/legal/epl-v10.html
   */
  
  package org.jboss.forge.git.gitignore;
  
 import java.io.File;
 import java.util.List;
 
 

Author(s):
Dan Allen
 
 {
 
    public static final String RESOURCE_NAME = ".gitignore";
 
    @Inject
    public GitIgnoreResource(ResourceFactory factory)
    {
       this(factorynull);
    }
 
    protected GitIgnoreResource(ResourceFactory factoryFile file)
    {
       super(factoryfile);
       setFlag(.);
    }
 
    @Override
    public Resource<FilecreateFrom(File file)
    {
       return new GitIgnoreResource(getResourceFactory(), file);
    }
 
    @Override
    protected List<Resource<?>> doListResources()
    {
       List<Resource<?>> patterns = new ArrayList<Resource<?>>();
       for (GitIgnoreEntry entry : getEntries())
       {
          if (entry.isPattern())
          {
             patterns.add(new GitIgnorePatternResource(thisentry.getContent()));
          }
       }
       return patterns;
    }
 
    public void addPattern(String pattern)
    {
       List<GitIgnoreEntryentries = getEntries();
       GitIgnoreEntry entry = new GitIgnoreEntry(pattern);
       if (!entries.contains(entry))
       {
          entries.add(entry);
          storeEntries(entries);
       }
    }
 
    public void addPatterns(String[] newPatterns)
    {
       List<GitIgnoreEntryentries = getEntries();
       boolean modified = false;
       for (String pattern : newPatterns)
       {
          GitIgnoreEntry entry = new GitIgnoreEntry(pattern);
          if (entries.contains(entry))
          {
             entries.add(entry);
             modified = true;
          }
       }
       if (modified)
       {
          storeEntries(entries);
       }
    }
 
    public void removePattern(String pattern)
    {
       List<GitIgnoreEntryentries = getEntries();
      GitIgnoreEntry entry = new GitIgnoreEntry(pattern);
      if (entries.contains(entry))
      {
         entries.remove(entry);
         storeEntries(entries);
      }
   }
   public List<StringgetPatterns()
   {
      List<Stringpatterns = new ArrayList<String>();
      for (GitIgnoreEntry entry : getEntries())
      {
         if (entry.isPattern())
         {
            patterns.add(entry.toString());
         }
      }
      return patterns;
   }
   {
      List<GitIgnoreEntrylines = new ArrayList<GitIgnoreEntry>();
      BufferedReader reader = null;
      try
      {
         reader = new BufferedReader(new InputStreamReader(getResourceInputStream()));
         String line = null;
         while ((line = reader.readLine()) != null)
         {
            lines.add(new GitIgnoreEntry(line));
         }
         return lines;
      }
      catch (IOException e)
      {
         throw new RuntimeException(
                  "Error while reading .gitignore patterns"e);
      }
      finally
      {
         Streams.closeQuietly(reader);
      }
   }
   protected void storeEntries(List<GitIgnoreEntryentries)
   {
      StringBuilder contents = new StringBuilder();
      for (GitIgnoreEntry entry : entries)
      {
         contents.append(entry.toString()).append("\n");
      }
      setContents(contents.toString());
   }
New to GrepCode? Check out our FAQ X