Пример #1
0
  /**
   * Initialize a new git repository.
   *
   * @param dir The directory in which to create a new .git/ folder and repository.
   */
  public static Git init(final DirectoryResource dir) throws IOException {
    FileResource<?> gitDir = dir.getChildDirectory(".git").reify(FileResource.class);
    gitDir.mkdirs();

    RepositoryBuilder db =
        new RepositoryBuilder().setGitDir(gitDir.getUnderlyingResourceObject()).setup();
    Git git = new Git(db.build());
    git.getRepository().create();
    return git;
  }
Пример #2
0
  @Override
  public FileResource<?> getConfigFile() {
    DirectoryResource webRoot = project.getFacet(WebResourceFacet.class).getWebRootDirectory();
    FileResource<?> child =
        (FileResource<?>) webRoot.getChild("WEB-INF" + File.separator + "faces-config.xml");

    if (!child.exists()) {
      return new UnknownFileResource(
          child.getResourceFactory(), child.getUnderlyingResourceObject()) {
        @Override
        public InputStream getResourceInputStream() {
          if (!exists()) {
            String projectName = project.getFacet(MetadataFacet.class).getProjectName();
            WebAppDescriptor unit =
                Descriptors.create(WebAppDescriptor.class)
                    .displayName(projectName)
                    .sessionTimeout(30);
            return Streams.fromString(unit.exportAsString());
          } else {
            return super.getResourceInputStream();
          }
        }

        @Override
        public UnknownFileResource setContents(InputStream data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }

        @Override
        public UnknownFileResource setContents(char[] data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }

        @Override
        public UnknownFileResource setContents(String data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }
      };
    }

    return (FileResource<?>) child;
  }