Esempio n. 1
0
 @Override
 public IFile createFile(String path) {
   File file = new File(context.absPath(path));
   String name = file.getName();
   String parentPath = file.getParent();
   try {
     VfsUtil.createDirectories(parentPath);
   } catch (IOException e) {
     Flog.error("Create directories error %s", e);
     context.errorMessage("The Floobits plugin was unable to create directories for file.");
     return null;
   }
   VirtualFile parent = LocalFileSystem.getInstance().findFileByPath(parentPath);
   if (parent == null) {
     Flog.error("Virtual file is null? %s", parentPath);
     return null;
   }
   VirtualFile newFile;
   try {
     newFile = parent.findOrCreateChildData(context, name);
   } catch (Throwable e) {
     Flog.error("Create file error %s", e);
     context.errorMessage(
         String.format("The Floobits plugin was unable to create a file: %s.", path));
     return null;
   }
   return new FileImpl(newFile);
 }
  @Override
  public void create(
      @NotNull Project project,
      @NotNull BuildSystem buildSystem,
      @NotNull ProgressIndicator indicator) {
    Util.runWriteTask(
        () -> {
          try {
            indicator.setText("Writing main class");
            VirtualFile file = buildSystem.getSourceDirectories().get(0);
            final String[] files = this.mainClass.split("\\.");
            final String className = files[files.length - 1];
            final String packageName =
                this.mainClass.substring(0, this.mainClass.length() - className.length() - 1);
            file = getMainClassDirectory(files, file);

            final VirtualFile mainClassFile = file.findOrCreateChildData(this, className + ".java");
            SpongeTemplate.applyMainClassTemplate(
                project,
                mainClassFile,
                packageName,
                className,
                hasDependencies(),
                generateDocumentedListeners);

            final PsiJavaFile mainClassPsi =
                (PsiJavaFile) PsiManager.getInstance(project).findFile(mainClassFile);
            if (mainClassPsi == null) {
              return;
            }
            final PsiClass psiClass = mainClassPsi.getClasses()[0];

            writeMainSpongeClass(
                project,
                mainClassPsi,
                psiClass,
                buildSystem,
                pluginName,
                description,
                website,
                hasAuthors(),
                authors,
                hasDependencies(),
                dependencies);

            EditorHelper.openInEditor(mainClassPsi);
          } catch (IOException e) {
            e.printStackTrace();
          }
        });
  }