/**
  * Try to load a config XML file from a named path. If the file does not exist, return
  * NONEXISTENT; or if there is any load error, return null.
  */
 private Document loadXml(String path) {
   assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
   assert Thread.holdsLock(modifiedMetadataPaths);
   FileObject xml = dir.getFileObject(path);
   if (xml == null || !xml.isData()) {
     return NONEXISTENT;
   }
   try {
     Document doc =
         XMLUtil.parse(
             new InputSource(xml.getInputStream()),
             false,
             true,
             XMLUtil.defaultErrorHandler(),
             null);
     return doc;
   } catch (IOException e) {
     if (!QUIETLY_SWALLOW_XML_LOAD_ERRORS) {
       LOG.log(Level.INFO, "Load XML: {0}", xml.getPath()); // NOI18N
       ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
     }
   } catch (SAXException e) {
     if (!QUIETLY_SWALLOW_XML_LOAD_ERRORS) {
       LOG.log(Level.INFO, "Load XML: {0}", xml.getPath()); // NOI18N
       ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
     }
   }
   return null;
 }
  protected @Override void setUp() throws Exception {
    MockLookup.setLayersAndInstances(TestUtil.testProjectFactory());
    ProjectManager.getDefault().reset();
    FileOwnerQuery.reset();
    scratch = TestUtil.makeScratchDir(this);
    projdir = scratch.createFolder("my-project");
    projdir.createFolder("testproject");
    randomfile = scratch.createData("randomfile");
    projfile = projdir.createData("projfile");
    FileObject projsubdir = projdir.createFolder("projsubdir");
    projfile2 = projsubdir.createData("projfile2");
    subprojdir = projdir.createFolder("subproject");
    subprojdir.createFolder("testproject");
    subprojfile = subprojdir.createData("subprojfile");
    scratch.createFolder("external1").createFolder("subdir").createData("file");
    scratch.createFolder("external2").createFolder("subdir").createData("file");
    scratch.createFolder("external3").createFolder("subproject").createFolder("testproject");
    p = ProjectManager.getDefault().findProject(projdir);
    assertNotNull("found a project successfully", p);

    // make jar:file:/.../projdir/foo.jar!/zipfile/zippedfile
    FileObject foojar = TestFileUtils.writeZipFile(projdir, "foo.jar", "zipdir/zippedfile:");
    FileObject foojarRoot = FileUtil.getArchiveRoot(foojar);
    assertNotNull("have an archive in " + foojar, foojarRoot);
    zippedfile = foojarRoot.getFileObject("zipdir/zippedfile");
    assertNotNull("zippedfile found in it", zippedfile);

    hashedFile = TestFileUtils.writeZipFile(projdir, ".#webapp.jar.1.45", "zipdir/zippedfile:");
    foojarRoot = FileUtil.getArchiveRoot(hashedFile);
    assertNotNull("have an archive in " + hashedFile, foojarRoot);
    hashedFile = foojarRoot.getFileObject("zipdir/zippedfile");
  }
  @NbBundle.Messages({
    "CakePhpCustomizerValidator.error.app.invalid=Existing app directory must be set.",
    "CakePhpCustomizerValidator.error.app.config.invalid=App directory must have config/Config directory."
  })
  public CakePhpCustomizerValidator validateAppPath(FileObject sourceDirectory, String path) {
    FileObject targetDirectory = sourceDirectory.getFileObject(path);
    if (targetDirectory == null) {
      result.addWarning(
          new ValidationResult.Message(
              "app.path", Bundle.CakePhpCustomizerValidator_error_app_invalid())); // NOI18N
      return this;
    }

    // Cake2.x
    FileObject config = targetDirectory.getFileObject("Config"); // NOI18N
    if (config == null) {
      // Cake1.x
      config = targetDirectory.getFileObject("config"); // NOI18N
    }
    if (config == null) {
      result.addWarning(
          new ValidationResult.Message(
              "app.config", Bundle.CakePhpCustomizerValidator_error_app_config_invalid()));
    }
    return this;
  }
 private boolean testIfFileNameExists(final SourceGroup preselectedGroup) {
   FileObject folder = null;
   if (preselectedGroup != null) folder = preselectedGroup.getRootFolder();
   if (folder == null) return false;
   final String pkg = getPackageFileName();
   if (pkg != null && !"".equals(pkg)) { // NOI18N
     folder = folder.getFileObject(pkg);
     if (folder == null) return false;
   }
   return folder.getFileObject(tClassName.getText() + expectedExtension) != null;
 }
 /**
  * Tests the issue 60297. GC causes previosly registered extenral roots for project to be
  * released. Only one extenral root per project is kept.
  */
 public void testIssue60297() throws Exception {
   FileObject ext1 = scratch.getFileObject("external1");
   assertEquals("no owner yet", null, FileOwnerQuery.getOwner(ext1));
   FileOwnerQuery.markExternalOwner(ext1, p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
   assertEquals("now have an owner", p, FileOwnerQuery.getOwner(ext1));
   FileObject ext2 = scratch.getFileObject("external2");
   assertEquals("no owner yet", null, FileOwnerQuery.getOwner(ext2));
   FileOwnerQuery.markExternalOwner(ext2, p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
   System.gc();
   assertEquals("now have an owner", p, FileOwnerQuery.getOwner(ext2));
   assertEquals("still correct for the first external root", p, FileOwnerQuery.getOwner(ext1));
 }
Esempio n. 6
0
  private void updateKeys() {
    List keys = new ArrayList();

    // Input and Output
    FileObject inputFO = mTestcaseDir.getFileObject("Input.xml"); // NOI18N
    if (inputFO != null) {
      keys.add(inputFO);
    }

    FileObject outputFO = mTestcaseDir.getFileObject("Output.xml"); // NOI18N
    if (outputFO != null) {
      keys.add(outputFO);
    }

    // Actual results
    FileObject realTestCaseResultsDir = getRealTestCaseResultsFolder();
    //        if (realTestCaseResultsDir != null) {
    //            if (realTestCaseResultsDir.getChildren().length > 0) {
    //                keys.add(realTestCaseResultsDir);
    //            }
    //        }
    //
    //        DataFolder dataFolder = DataFolder.findFolder(mTestCaseResultsDir);
    if (realTestCaseResultsDir != null) {
      FileObject[] resultFileObjects = realTestCaseResultsDir.getChildren();
      List resultKeys = new ArrayList();
      for (int i = 0; i < resultFileObjects.length; i++) {
        FileObject fo = resultFileObjects[i];
        if (isValidTestCaseResult(fo)) {
          resultKeys.add(fo);
        }
      }

      Collections.sort(
          resultKeys,
          new Comparator() {
            public int compare(Object obj1, Object obj2) {
              if ((obj1 instanceof FileObject) && (obj2 instanceof FileObject)) {
                FileObject fo1 = (FileObject) obj1;
                FileObject fo2 = (FileObject) obj2;

                return fo2.getNameExt().compareTo(fo1.getNameExt());
              } else {
                return 0;
              }
            }
          });

      keys.addAll(resultKeys);
    }

    setKeys(keys);
  }
Esempio n. 7
0
  private FileObject getRealTestCaseResultsFolder() {
    FileObject dir = null;

    String testcaseName = mTestcaseDir.getNameExt();
    FileObject testDir = mProject.getTestDirectory();
    if (testDir != null) {
      FileObject testResultsDir = testDir.getFileObject("results"); // TMP  // NOI18N
      if (testResultsDir != null) {
        dir = testResultsDir.getFileObject(testcaseName);
      }
    }

    return dir;
  }
 public void testFindTestSources() throws Exception {
   NbModuleProject p = generateStandaloneModule("p");
   FileObject test = p.getTestSourceDirectory("unit");
   FileObject oneTest = FileUtil.createData(test, "p/OneTest.java");
   FileObject r = FileUtil.createData(test, "p/r.png");
   FileObject otherTest = FileUtil.createData(test, "p/OtherTest.java");
   FileObject pkg = test.getFileObject("p");
   FileObject thirdTest = FileUtil.createData(test, "p2/ThirdTest.java");
   ModuleActions a = new ModuleActions(p);
   assertEquals("null", String.valueOf(a.findTestSources(Lookup.EMPTY, false)));
   assertEquals(
       "unit:p/OneTest.java",
       String.valueOf(a.findTestSources(Lookups.singleton(oneTest), false)));
   assertEquals(
       "unit:p/OneTest.java,p/OtherTest.java",
       String.valueOf(a.findTestSources(Lookups.fixed(oneTest, otherTest), false)));
   assertEquals("null", String.valueOf(a.findTestSources(Lookups.singleton(pkg), false)));
   assertEquals("null", String.valueOf(a.findTestSources(Lookups.singleton(r), false)));
   assertEquals("null", String.valueOf(a.findTestSources(Lookups.fixed(oneTest, r), false)));
   assertEquals("null", String.valueOf(a.findTestSources(Lookup.EMPTY, true)));
   assertEquals(
       "unit:p/OneTest.java", String.valueOf(a.findTestSources(Lookups.singleton(oneTest), true)));
   assertEquals(
       "unit:p/OneTest.java,p/OtherTest.java",
       String.valueOf(a.findTestSources(Lookups.fixed(oneTest, otherTest), true)));
   assertEquals("unit:p/**", String.valueOf(a.findTestSources(Lookups.singleton(pkg), true)));
   assertEquals(
       "unit:p/**,p2/ThirdTest.java",
       String.valueOf(a.findTestSources(Lookups.fixed(pkg, thirdTest), true)));
   assertEquals("null", String.valueOf(a.findTestSources(Lookups.singleton(r), true)));
   assertEquals("null", String.valueOf(a.findTestSources(Lookups.fixed(oneTest, r), true)));
 }
  public void savePreset(String name, Layout layout) {
    Preset preset = addPreset(new Preset(name, layout));

    try {
      // Create file if dont exist
      FileObject folder = FileUtil.getConfigFile("layoutpresets");
      if (folder == null) {
        folder = FileUtil.getConfigRoot().createFolder("layoutpresets");
      }
      FileObject presetFile = folder.getFileObject(name, "xml");
      if (presetFile == null) {
        presetFile = folder.createData(name, "xml");
      }

      // Create doc
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder documentBuilder = factory.newDocumentBuilder();
      final Document document = documentBuilder.newDocument();
      document.setXmlVersion("1.0");
      document.setXmlStandalone(true);

      // Write doc
      preset.writeXML(document);

      // Write XML file
      Source source = new DOMSource(document);
      Result result = new StreamResult(FileUtil.toFile(presetFile));
      Transformer transformer = TransformerFactory.newInstance().newTransformer();
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
      transformer.transform(source, result);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @BeforeClass
  public static void setUpClass() throws Exception {
    MockServices.setServices();
    DalvikPlatformManager.getDefault().setSdkLocation(SDK_DIR);
    tempFolder = File.createTempFile("junit", "");
    tempFolder.delete();
    tempFolder.mkdir();

    FileObject scratch = FileUtil.toFileObject(tempFolder);
    FileObject cacheDir = scratch.createFolder("cache");
    CacheFolder.setCacheFolder(cacheDir);
    FileObject sdkDirFo = FileUtil.toFileObject(new File(SDK_DIR));

    projdir = scratch.createFolder("Snake");
    FileUtilities.recursiveCopy(sdkDirFo.getFileObject("samples/android-8/Snake"), projdir);

    FileObject dir = projdir;
    for (String dirName : Splitter.on('/').split("gen/com/example/android/snake")) {
      dir = dir.createFolder(dirName);
    }
    OutputStream os = dir.createData("R.java").getOutputStream();
    FileUtil.copy(ProjectRefResolverTest.class.getResourceAsStream("Snake_R_java.txt"), os);
    os.close();

    pp = ProjectManager.getDefault().findProject(projdir);
  }
Esempio n. 11
0
  private FileObject getFolder() throws IOException {
    if (folder == null) {
      Project p = file.getLookup().lookup(Project.class);
      if (p != null) {
        root = p.getProjectDirectory();

        FileObject jmedataFolder = root.getFileObject("/nbproject/jme3Data");
        if (jmedataFolder == null) {
          jmedataFolder = root.getFileObject("/nbproject");
          if (jmedataFolder != null) {
            jmedataFolder = jmedataFolder.createFolder("jme3Data");
          }
        }
        return jmedataFolder;
      }
    }
    return folder;
  }
 private FileObject getSubdir(FileObject fo, String... subdirs) {
   for (String s : subdirs) {
     if (fo == null) {
       return null;
     }
     fo = fo.getFileObject(s);
   }
   return fo;
 }
Esempio n. 13
0
 public Transferable paste() throws IOException {
   assert this.op != DnDConstants.ACTION_NONE;
   for (int ni = 0; ni < nodes.length; ni++) {
     FileObject fo = srcRoot;
     if (!nodes[ni].isDefaultPackage) {
       String pkgName = nodes[ni].getName();
       StringTokenizer tk = new StringTokenizer(pkgName, "."); // NOI18N
       while (tk.hasMoreTokens()) {
         String name = tk.nextToken();
         FileObject tmp = fo.getFileObject(name, null);
         if (tmp == null) {
           tmp = fo.createFolder(name);
         }
         fo = tmp;
       }
     }
     DataFolder dest = DataFolder.findFolder(fo);
     DataObject[] children = nodes[ni].dataFolder.getChildren();
     boolean cantDelete = false;
     for (int i = 0; i < children.length; i++) {
       if (children[i].getPrimaryFile().isData()
           && VisibilityQuery.getDefault().isVisible(children[i].getPrimaryFile())) {
         // Copy only the package level
         children[i].copy(dest);
         if (this.op == DnDConstants.ACTION_MOVE) {
           try {
             children[i].delete();
           } catch (IOException ioe) {
             cantDelete = true;
           }
         }
       } else {
         cantDelete = true;
       }
     }
     if (this.op == DnDConstants.ACTION_MOVE && !cantDelete) {
       try {
         FileObject tmpFo = nodes[ni].dataFolder.getPrimaryFile();
         FileObject originalRoot = nodes[ni].root;
         assert tmpFo != null && originalRoot != null;
         while (!tmpFo.equals(originalRoot)) {
           if (tmpFo.getChildren().length == 0) {
             FileObject tmpFoParent = tmpFo.getParent();
             tmpFo.delete();
             tmpFo = tmpFoParent;
           } else {
             break;
           }
         }
       } catch (IOException ioe) {
         // Not important
       }
     }
   }
   return ExTransferable.EMPTY;
 }
  public void testExternalOwnerFile() throws Exception {
    FileObject ext1 = scratch.getFileObject("external1");
    FileObject extfile1 = ext1.getFileObject("subdir/file");
    assertEquals("no owner yet", null, FileOwnerQuery.getOwner(extfile1));
    FileOwnerQuery.markExternalOwner(extfile1, p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    assertEquals("now have an owner", p, FileOwnerQuery.getOwner(extfile1));
    assertEquals("not for the projdir", null, FileOwnerQuery.getOwner(ext1));
    assertEquals("and not for something else", null, FileOwnerQuery.getOwner(scratch));
    FileObject ext2 = scratch.getFileObject("external2");
    FileObject extfile2 = ext2.getFileObject("subdir/file");
    assertEquals("no owner yet", null, FileOwnerQuery.getOwner(extfile2));
    Project p2 = ProjectManager.getDefault().findProject(subprojdir);
    FileOwnerQuery.markExternalOwner(extfile2, p2, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    assertEquals("now have an owner", p2, FileOwnerQuery.getOwner(extfile2));
    assertEquals("not for the projdir", null, FileOwnerQuery.getOwner(ext2));
    assertEquals("and not for something else", null, FileOwnerQuery.getOwner(scratch));
    assertEquals("still correct for first proj", p, FileOwnerQuery.getOwner(extfile1));

    // XXX: unmarking files.
  }
Esempio n. 15
0
 public static void registerXMLKit() {
   String[] path = new String[] {"Editors", "text", "x-xml"};
   FileObject target = FileUtil.getConfigRoot();
   try {
     for (int i = 0; i < path.length; i++) {
       FileObject f = target.getFileObject(path[i]);
       if (f == null) {
         f = target.createFolder(path[i]);
       }
       target = f;
     }
     String name = "EditorKit.instance";
     if (target.getFileObject(name) == null) {
       FileObject f = target.createData(name);
       f.setAttribute("instanceClass", "org.netbeans.modules.xml.text.syntax.XMLKit");
     }
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }
Esempio n. 16
0
 private void checkDBFolder(FileObject rootFolder) {
   if (rootFolder != null) {
     dbFolder = rootFolder.getFileObject(DB_DIR);
     if (dbFolder == null) {
       try {
         dbFolder = rootFolder.createFolder(DB_DIR);
       } catch (IOException e) {
         // probably exists or cannot be created
       }
     }
   }
 }
 private FileObject findTestDir(TmcProjectInfo projectInfo) {
   // Ideally we'd get these paths from NB, but let's assume the conventional ones for now.
   FileObject root = projectInfo.getProjectDir();
   switch (projectInfo.getProjectType()) {
     case JAVA_SIMPLE:
       return root.getFileObject("test");
     case JAVA_MAVEN:
       return getSubdir(root, "src", "test", "java");
     default:
       throw new IllegalArgumentException("Unknown project type");
   }
 }
 public void testExternalOwner() throws Exception {
   FileObject ext1 = scratch.getFileObject("external1");
   FileObject extfile1 = ext1.getFileObject("subdir/file");
   assertEquals("no owner yet", null, FileOwnerQuery.getOwner(extfile1));
   FileOwnerQuery.markExternalOwner(ext1, p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
   assertEquals("now have an owner", p, FileOwnerQuery.getOwner(extfile1));
   assertEquals("even for the projdir", p, FileOwnerQuery.getOwner(ext1));
   assertEquals("but not for something else", null, FileOwnerQuery.getOwner(scratch));
   FileObject ext2 = scratch.getFileObject("external2");
   FileObject extfile2 = ext2.getFileObject("subdir/file");
   assertEquals("no owner yet", null, FileOwnerQuery.getOwner(extfile2));
   Project p2 = ProjectManager.getDefault().findProject(subprojdir);
   FileOwnerQuery.markExternalOwner(ext2, p2, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
   assertEquals("now have an owner", p2, FileOwnerQuery.getOwner(extfile2));
   assertEquals("even for the projdir", p2, FileOwnerQuery.getOwner(ext2));
   assertEquals("but not for something else", null, FileOwnerQuery.getOwner(scratch));
   assertEquals("still correct for first proj", p, FileOwnerQuery.getOwner(extfile1));
   FileObject ext3 = scratch.getFileObject("external3");
   assertEquals("no owner yet", null, FileOwnerQuery.getOwner(ext3));
   FileOwnerQuery.markExternalOwner(ext3, p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
   assertEquals("now have an owner", p, FileOwnerQuery.getOwner(ext3));
   FileObject ext3subproj = ext3.getFileObject("subproject");
   Project p3 = FileOwnerQuery.getOwner(ext3subproj);
   assertNotSame("different project", p, p3);
   assertEquals(
       "but subprojects are not part of it",
       ProjectManager.getDefault().findProject(ext3subproj),
       p3);
   FileOwnerQuery.markExternalOwner(ext3, null, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
   assertEquals("unmarking an owner works", null, FileOwnerQuery.getOwner(ext3));
 }
 private static void setModules(final FileObject dir, final WizardDescriptor wiz) {
   final Properties properties =
       (Properties) wiz.getProperty(ModuleSelectionWizardPanel1.MODULE_SELECTION_PROPS);
   if (properties != null) {
     final FileObject jinferProjectDir = dir.getFileObject("jinferproject");
     try {
       final FileObject projectProperties = jinferProjectDir.createData("project", "properties");
       properties.store(new FileOutputStream(FileUtil.toFile(projectProperties)), null);
     } catch (IOException ex) {
       Exceptions.printStackTrace(ex);
     }
   }
 }
  public void testIsProjectDirCollectible() throws Exception {
    Project p2 = ProjectManager.getDefault().findProject(subprojdir);
    FileObject root = p2.getProjectDirectory();
    FileObject ext2 = scratch.getFileObject("external2");
    FileObject extfile2 = ext2.getFileObject("subdir/file");

    FileOwnerQuery.markExternalOwner(
        extfile2.toURI(), p2, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);

    Reference<?> p2WR = new WeakReference<Object>(p2);
    Reference<?> rootWR = new WeakReference<Object>(root);

    p2 = null;
    root = null;
    ext2 = null;
    extfile2 = null;
    subprojdir = null;
    subprojfile = null;

    assertGC("project 2 collected", p2WR);
    assertGC("project 2's project dir collected", rootWR);
  }
 protected Properties getWebAppsProperties() {
   Properties props = new Properties();
   FileObject target = getRegistry();
   if (target == null) {
     return props;
   }
   FileObject propsFo = target.getFileObject(SuiteConstants.SERVER_INSTANCE_WEB_APPS_PROPS);
   if (propsFo == null) {
     return props;
   }
   props = BaseUtil.loadProperties(propsFo);
   return props;
 }
 public void testJavadocFolders() throws Exception {
   final File wd = this.getWorkDir();
   final FileObject wdfo = FileUtil.toFileObject(wd);
   final FileObject golden1 =
       FileUtil.createFolder(wdfo, "test1/docs/api/index-files").getParent(); // NOI18N
   final FileObject golden2 =
       FileUtil.createFolder(wdfo, "test2/docs/ja/api/index-files").getParent(); // NOI18N
   FileObject testFo = wdfo.getFileObject("test1"); // NOI18N
   FileObject res = JavadocForBinaryQueryPlatformImpl.R.findIndexFolder(testFo);
   assertEquals(res, golden1);
   testFo = wdfo.getFileObject("test1/docs"); // NOI18N
   res = JavadocForBinaryQueryPlatformImpl.R.findIndexFolder(testFo);
   assertEquals(res, golden1);
   testFo = wdfo.getFileObject("test2"); // NOI18N
   res = JavadocForBinaryQueryPlatformImpl.R.findIndexFolder(testFo);
   assertEquals(res, golden2);
   testFo = wdfo.getFileObject("test2/docs"); // NOI18N
   res = JavadocForBinaryQueryPlatformImpl.R.findIndexFolder(testFo);
   assertEquals(res, golden2);
   testFo = wdfo.getFileObject("test2/docs/ja"); // NOI18N
   res = JavadocForBinaryQueryPlatformImpl.R.findIndexFolder(testFo);
   assertEquals(res, golden2);
 }
 public void testExternalOwnerDisappearingProject() throws Exception {
   FileObject ext1 = scratch.getFileObject("external1");
   FileObject tempPrjMarker = FileUtil.createFolder(scratch, "tempprj/testproject");
   FileObject tempPrjDir = tempPrjMarker.getParent();
   Project tempPrj = ProjectManager.getDefault().findProject(tempPrjDir);
   assertNotNull(tempPrj);
   FileOwnerQuery.markExternalOwner(
       ext1.toURI(), tempPrj, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
   assertEquals("now have an owner", tempPrj, FileOwnerQuery.getOwner(ext1));
   Reference<FileObject> r = new WeakReference<FileObject>(tempPrjDir);
   tempPrjMarker = tempPrjDir = null;
   tempPrj = null;
   assertGC("can be GCed", r);
   assertNotNull("still has an owner", FileOwnerQuery.getOwner(ext1));
 }
Esempio n. 24
0
 public static void addDirectory(final FileObject baseDir, final String targetPath) {
   try {
     final String[] dirs = targetPath.split("/");
     FileObject fo = baseDir;
     for (int i = 0; i < dirs.length; i++) {
       final FileObject child = fo.getFileObject(dirs[i]);
       if (child != null) {
         fo = child;
       } else {
         fo = fo.createFolder(dirs[i]);
       }
     }
   } catch (final IOException ex) {
     Exceptions.printStackTrace(ex);
   }
 }
  @NbBundle.Messages({
    "CakePhpCustomizerValidator.error.dotcake.notFound=[.cake] Existing .cake file must be set.",
    "CakePhpCustomizerValidator.error.dotcake.notFile=[.cake] File path must be set.",
    "CakePhpCustomizerValidator.error.dotcake.invalid.file.format=[.cake] Invalid format. Can't get data from .cake.",
    "CakePhpCustomizerValidator.error.dotcake.invalid.file.name=[.cake] File name must be .cake."
  })
  public CakePhpCustomizerValidator validateDotcakeFilePath(
      FileObject sourceDirectory, String path) {
    // ignore if file path is empy
    if (StringUtils.isEmpty(path)) {
      return this;
    }

    FileObject targetFile = sourceDirectory.getFileObject(path);
    if (targetFile == null) {
      result.addWarning(
          new ValidationResult.Message(
              "dotcake.path",
              Bundle.CakePhpCustomizerValidator_error_dotcake_notFound())); // NOI18N
      return this;
    }

    if (targetFile.isFolder()) {
      result.addWarning(
          new ValidationResult.Message(
              "dotcake.path", Bundle.CakePhpCustomizerValidator_error_dotcake_notFile())); // NOI18N
      return this;
    }

    if (!targetFile.getNameExt().equals(".cake")) { // NOI18N
      result.addWarning(
          new ValidationResult.Message(
              "dotcake.path",
              Bundle.CakePhpCustomizerValidator_error_dotcake_invalid_file_name())); // NOI18N
      return this;
    }

    // invalid format
    Dotcake dotcake = Dotcake.fromJson(targetFile);
    if (dotcake == null || dotcake.getCake() == null || dotcake.getBuildPath() == null) {
      result.addWarning(
          new ValidationResult.Message(
              "dotcake.path",
              Bundle.CakePhpCustomizerValidator_error_dotcake_invalid_file_format())); // NOI18N
    }
    return this;
  }
 private ClassPath getTestRunnerClassPath(TmcProjectInfo projectInfo) {
   FileObject projectDir = projectInfo.getProjectDir();
   FileObject testrunnerDir = projectDir.getFileObject("lib/testrunner");
   if (testrunnerDir != null) {
     FileObject[] files = testrunnerDir.getChildren();
     ArrayList<URL> urls = new ArrayList<URL>();
     for (FileObject file : files) {
       URL url = FileUtil.urlForArchiveOrDir(FileUtil.toFile(file));
       if (url != null) {
         urls.add(url);
       }
     }
     return ClassPathSupport.createClassPath(urls.toArray(new URL[0]));
   } else {
     return null;
   }
 }
Esempio n. 27
0
  @Override
  public RunCommandAction getRunCommandAction() {
    // check whether yiic.php exists
    // if it doesn't exist, doesn't add this action
    PhpModule phpModule = PhpModule.Factory.inferPhpModule();
    YiiModule yiiModule = YiiModuleFactory.create(phpModule);
    FileObject webroot = yiiModule.getWebroot();
    if (webroot == null) {
      return null;
    }

    FileObject yiic = webroot.getFileObject("protected/yiic.php"); // NOI18N
    if (yiic == null && StringUtils.isEmpty(YiiOptions.getInstance().getYiiScript())) {
      return null;
    }
    return YiiRunCommandAction.getInstance();
  }
Esempio n. 28
0
  private File getStorageFile() {
    File storage = null;
    if (dbFolder != null) {
      FileObject storageFO = dbFolder.getFileObject(STORAGE, STORAGE_EXT);
      try {
        if (storageFO == null) {
          storageFO = dbFolder.createData(STORAGE, STORAGE_EXT);
        }
      } catch (IOException e) {
      }

      if (storageFO != null) {
        storage = NbClassPath.toFile(storageFO);
      }
    }
    return storage;
  }
 @Override
 public FileObject resolveFileObject(String filename) throws IllegalArgumentException {
   if (filename == null) {
     throw new NullPointerException("null filename passed to resolveFile"); // NOI18N
   }
   FileObject f;
   if (RELATIVE_SLASH_SEPARATED_PATH.matcher(filename).matches()) {
     return dir.getFileObject(filename);
   } else {
     try {
       return dir.getFileSystem().findResource(filename);
     } catch (FileStateInvalidException ex) {
       Exceptions.printStackTrace(ex);
       return null;
     }
   }
 }
Esempio n. 30
0
 protected Node[] createNodes(Object obj) {
   FileObject fo = root.getFileObject((String) obj);
   if (fo != null && fo.isValid()) {
     Object o = names2nodes.get(obj);
     PackageNode n;
     if (o == NODE_NOT_CREATED) {
       n = new PackageNode(root, DataFolder.findFolder(fo), false);
     } else if (o == NODE_NOT_CREATED_EMPTY) {
       n = new PackageNode(root, DataFolder.findFolder(fo), true);
     } else {
       n = new PackageNode(root, DataFolder.findFolder(fo));
     }
     names2nodes.put(obj, n);
     return new Node[] {n};
   } else {
     return new Node[0];
   }
 }