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.maven.facets;
  
  import java.io.File;
 import java.util.List;
 
 

Author(s):
Lincoln Baxter, III
 
 @Alias("forge.maven.ResourceFacet")
 public class MavenResourceFacet extends BaseFacet implements ResourceFacetFacet
 {
    private Project project;
 
    @Override
    {
       List<DirectoryResourceresult = new ArrayList<DirectoryResource>();
       result.add(getResourceFolder());
       result.add(getTestResourceFolder());
       return result;
    }
 
    @Override
    {
       MavenCoreFacet mavenFacet = .getFacet(MavenCoreFacet.class);
       Build build = mavenFacet.getPOM().getBuild();
       final String resFolderName;
       if (build != null && !build.getResources().isEmpty() && build.getResources().get(0).getDirectory() != null)
       {
          resFolderName = build.getResources().get(0).getDirectory();
       }
       else
       {
          resFolderName = "src" + . + "main" + . + "resources";
       }
       DirectoryResource projectRoot = .getProjectRoot();
       return projectRoot.getChildDirectory(resFolderName);
    }
 
    @Override
    {
       MavenCoreFacet mavenFacet = .getFacet(MavenCoreFacet.class);
       Build build = mavenFacet.getPOM().getBuild();
       final String resFolderName;
       if (build != null && !build.getTestResources().isEmpty()
                && build.getTestResources().get(0).getDirectory() != null)
       {
          resFolderName = build.getTestResources().get(0).getDirectory();
       }
       else
       {
          resFolderName = "src" + . + "test" + . + "resources";
       }
       DirectoryResource projectRoot = .getProjectRoot();
       return projectRoot.getChildDirectory(resFolderName);
    }
 
    @Override
    public Project getProject()
    {
       return ;
    }
 
    @Override
    public void setProject(final Project project)
    {
       this. = project;
    }
 
    @Override
    public boolean isInstalled()
    {
       try
       {
         .getFacet(MavenCoreFacet.class);
         return getResourceFolder().exists();
      }
      catch (FacetNotFoundException e)
      {
         return false;
      }
   }
   public boolean install()
   {
      if (!this.isInstalled())
      {
         for (DirectoryResource folder : this.getResourceFolders())
         {
            folder.mkdirs();
         }
      }
      return true;
   }
   public FileResource<?> getResource(final String relativePath)
   {
      return (FileResource<?>) getResourceFolder().getChild(relativePath);
   }
   public FileResource<?> getTestResource(final String relativePath)
   {
      return (FileResource<?>) getTestResourceFolder().getChild(relativePath);
   }
   public FileResource<?> createResource(final char[] bytesfinal String relativeFilename)
   {
      FileResource<?> file = (FileResource<?>) getResourceFolder().getChild(relativeFilename);
      file.setContents(bytes);
      return file;
   }
   public FileResource<?> createTestResource(final char[] bytesfinal String relativeFilename)
   {
      FileResource<?> file = (FileResource<?>) getTestResourceFolder().getChild(relativeFilename);
      file.setContents(bytes);
      return file;
   }
New to GrepCode? Check out our FAQ X