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;
 
 
 
 @Alias("forge.vcs.git.ignore")
 public class GitIgnoreFacet extends BaseFacet
 {
    public static final String GITIGNORE = ".gitignore";
 
    private static final String GLOBAL_TEMPLATES = "Global";
 
    @Inject
    private GitIgnoreConfig config;
 
    @Inject
    private ResourceFactory factory;
 
    @Inject
    private Shell shell;
 
    @Override
    public boolean install()
    {
       try
       {
          DirectoryResource cloneDir = cloneDir();
          String repo = .remoteRepository();
          ShellMessages.info("Cloning " + repo + " into " + cloneDir.getFullyQualifiedName());
          Git git = GitUtils.clone(cloneDirrepo);
          GitUtils.close(git);
          return true;
       }
       catch (Exception e)
       {
          ShellMessages.error("Failed to checkout gitignore: " + e);
          return false;
       }
    }
 
    @Override
    public boolean isInstalled()
    {
       File clone = .localRepository();
       Resource<FilecloneDir = .getResourceFrom(clone);
       return cloneDir.exists() && cloneDir.getChild(".git").exists();
    }

   
List all available gitignore templates.
 
    public List<GitIgnoreTemplateGrouplist()
    {
       List<GitIgnoreTemplateGroupresult = new ArrayList<GitIgnoreTemplateGroup>(2);
       DirectoryResource languages = cloneDir();
       result.add(new GitIgnoreTemplateGroup("Languages"listGitignores(languages)));
       result.add(new GitIgnoreTemplateGroup("Globals"listGitignores(languages.getChildDirectory())));
       return result;
    }

   
Read the content of a gitignore template

Parameters:
template Template name.
Returns:
Template content as string.
 
    @SuppressWarnings("unchecked")
    public String contentOf(String template)
    {
       DirectoryResource[] candidates = new DirectoryResource[] {
               cloneDir(), cloneDir().getChildDirectory()
      };
      for (DirectoryResource dir : candidates)
      {
         if (listGitignores(dir).contains(template))
         {
            FileResource<?> file = dir.getChildOfType(FileResource.classtemplate + );
            return Streams.toString(file.getResourceInputStream());
         }
      }
      return "";
   }

   
Update the templates from the remote repository.

Throws:
java.io.IOException Failure reading the git repository.
org.eclipse.jgit.api.errors.GitAPIException Git failure.
   public void update() throws IOExceptionGitAPIException
   {
      Git git = GitUtils.git(cloneDir());
      GitUtils.pull(git, 10000);
      GitUtils.close(git);
   }
   {
      List<Stringresult = new LinkedList<String>();
      ResourceFilter filter = new ResourceFilter()
      {
         @Override
         public boolean accept(Resource<?> resource)
         {
            return resource.getName().endsWith();
         }
      };
      for (Resource<?> resource : dir.listResources(filter))
      {
         String name = resource.getName();
         String cut = name.substring(0, name.indexOf());
         result.add(cut);
      }
      return result;
   }
   private DirectoryResource cloneDir()
   {
      return new DirectoryResource(.localRepository());
   }
New to GrepCode? Check out our FAQ X