@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);
  }
Exemplo n.º 2
0
  public void testDeleteCreateFile() throws IOException {

    // non atomic delete and create
    File file1 = new File(dataRootDir, "file1");
    file1 = FileUtil.normalizeFile(file1);
    file1.createNewFile();

    final FileObject fo1 = FileUtil.toFileObject(file1);
    fo1.delete();
    fo1.getParent().createData(fo1.getName());

    // get intercepted events
    String[] nonAtomic =
        DeleteCreateTestAnnotationProvider.instance.events.toArray(
            new String[DeleteCreateTestAnnotationProvider.instance.events.size()]);
    DeleteCreateTestAnnotationProvider.instance.events.clear();

    // atomic delete and create
    File file2 = new File(dataRootDir, "file2");
    file2 = FileUtil.normalizeFile(file2);
    file2.createNewFile();

    final FileObject fo2 = FileUtil.toFileObject(file2);
    AtomicAction a =
        new AtomicAction() {
          public void run() throws IOException {
            fo2.delete();
            fo2.getParent().createData(fo2.getName());
          }
        };
    fo2.getFileSystem().runAtomicAction(a);
    // get intercepted events
    String[] atomic =
        DeleteCreateTestAnnotationProvider.instance.events.toArray(
            new String[DeleteCreateTestAnnotationProvider.instance.events.size()]);

    Logger l = Logger.getLogger(DeleteCreateTest.class.getName());
    l.info("- atomic events ----------------------------------");
    for (String s : atomic) l.info(s);
    l.info("- non atomic events ------------------------------");
    for (String s : nonAtomic) l.info(s);
    l.info("-------------------------------");

    // test
    assertEquals(atomic.length, nonAtomic.length);
    for (int i = 0; i < atomic.length; i++) {
      assertEquals(atomic[i], nonAtomic[i]);
    }
  }
Exemplo n.º 3
0
  /** Like mkdirs but but using openide filesystems (firing events) */
  public static FileObject mkfolders(File file) throws IOException {
    file = FileUtil.normalizeFile(file);
    if (file.isDirectory()) return FileUtil.toFileObject(file);

    File parent = file.getParentFile();

    String path = file.getName();
    while (parent.isDirectory() == false) {
      path = parent.getName() + "/" + path; // NOI18N
      parent = parent.getParentFile();
    }

    FileObject fo = FileUtil.toFileObject(parent);
    return FileUtil.createFolder(fo, path);
  }
  private void onDeploy() {
    if (isCompleteImmediately()) {
      return;
    }

    List<Pair<BaseTargetModuleID, BaseTargetModuleID>> modules =
        getManager().getInitialDeployedModulesOld();
    Project wp =
        BaseUtil.getOwnerProject(
            FileUtil.toFileObject(new File(getTargetModuleID().getProjectDir())));

    int i = 0;
    for (Pair<BaseTargetModuleID, BaseTargetModuleID> pair : modules) {
      if (pair.first().getContextPath().equals(getTargetModuleID().getContextPath())) {
        modules.set(i, Pair.of(getTargetModuleID(), (BaseTargetModuleID) null));
        return;
      }
      i++;
    }
    i = 0;
    for (Pair<BaseTargetModuleID, BaseTargetModuleID> pair : modules) {
      if (pair.first().getProjectDir().equals(getTargetModuleID().getProjectDir())) {
        modules.set(i, Pair.of(getTargetModuleID(), (BaseTargetModuleID) null));
        return;
      }
      i++;
    }

    modules.add(Pair.of(getTargetModuleID(), (BaseTargetModuleID) null));
    //      }
  }
 /**
  * Create a scratch directory for tests. Will be in /tmp or whatever, and will be empty. If you
  * just need a java.io.File use clearWorkDir + getWorkDir.
  */
 public static FileObject makeScratchDir(NbTestCase test) throws IOException {
   boolean warned = false;
   test.clearWorkDir();
   File root = test.getWorkDir();
   assert root.isDirectory() && root.list().length == 0;
   FileObject fo = FileUtil.toFileObject(root);
   if (fo != null) {
     return fo;
   } else {
     if (!warned) {
       warned = true;
       System.err.println(
           "No FileObject for "
               + root
               + " found.\n"
               + "Maybe you need ${openide/masterfs.dir}/modules/org-netbeans-modules-masterfs.jar\n"
               + "in test.unit.run.cp.extra, or make sure Lookups.metaInfServices is included in Lookup.default, so that\n"
               + "Lookup.default<URLMapper>="
               + Lookup.getDefault().lookup(new Lookup.Template(URLMapper.class)).allInstances()
               + " includes MasterURLMapper\n"
               + "e.g. by using TestUtil.setLookup(Object[]) rather than TestUtil.setLookup(Lookup).");
     }
     // For the benefit of those not using masterfs.
     LocalFileSystem lfs = new LocalFileSystem();
     try {
       lfs.setRootDirectory(root);
     } catch (PropertyVetoException e) {
       assert false : e;
     }
     Repository.getDefault().addFileSystem(lfs);
     return lfs.getRoot();
   }
 }
 public FileObject copyFile(FileObject source) {
   FileObject result = null;
   Path target = createRegistry().resolve(source.getNameExt());
   if (Files.exists(target)) {
     result = FileUtil.toFileObject(target.toFile());
   } else {
     Path sourcePath = FileUtil.toFile(source).toPath();
     try {
       Path p = Files.copy(sourcePath, target);
       result = FileUtil.toFileObject(p.toFile());
     } catch (IOException ex) {
       LOG.log(Level.INFO, ex.getMessage());
     }
   }
   return result;
 }
  public Set /*<FileObject>*/ instantiate(/*ProgressHandle handle*/ ) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
      FileObject subfolder = e.nextElement();
      if (ProjectManager.getDefault().isProject(subfolder)) {
        resultSet.add(subfolder);
      }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
      ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
  }
Exemplo n.º 8
0
  public static boolean isIgnored(File file, boolean checkSharability) {
    if (file == null) {
      return false;
    }

    File topFile = Git.getInstance().getTopmostManagedParent(file);
    // We assume that the toplevel directory should not be ignored.
    if (topFile == null || topFile.equals(file)) {
      return false; // We assume that the Project should not be ignored.
    }
    if (file.isDirectory()) {
      ProjectManager projectManager = ProjectManager.getDefault();
      if (projectManager.isProject(FileUtil.toFileObject(file))) {
        return false;
      }
    }

    Repository repo = Git.getInstance().getRepository(topFile);
    ExcludeCache cache = getCache(repo);
    if (cache.isExcluded(file)) return true;

    if (file.getName().equals(".gitignore")
        || file.getName().equals(".gitattributes")
        || file.getName().equals(".gitmodules")) return false;

    if (checkSharability && !isSharable(file)) {
      return true;
    }
    return false;
  }
  public static synchronized List<String> getServerInstanceIds(FileObject suiteDir) {

    if (suiteDir == null) {
      return null;
    }
    Path suitePath = Paths.get(suiteDir.getPath());
    Deployment d = Deployment.getDefault();

    if (d == null || d.getServerInstanceIDs() == null) {
      return null;
    }
    List<String> result = new ArrayList<>();
    for (String uri : d.getServerInstanceIDs()) {
      InstanceProperties ip = InstanceProperties.getInstanceProperties(uri);

      String foundSuiteLocation = SuiteUtil.getSuiteProjectLocation(ip);
      if (foundSuiteLocation == null || !new File(foundSuiteLocation).exists()) {
        // May be not a native plugin server
        continue;
      }
      Project foundSuite =
          BaseUtil.getOwnerProject(FileUtil.toFileObject(new File(foundSuiteLocation)));

      if (foundSuite == null) {
        continue;
      }
      Path p = Paths.get(foundSuiteLocation);

      if (suitePath.equals(p)) {
        result.add(uri);
      }
    }
    return result;
  }
Exemplo n.º 10
0
  public static String getProjectName(final File root) {
    if (root == null || !root.isDirectory()) {
      return null;
    }
    final ProjectManager projectManager = ProjectManager.getDefault();
    FileObject rootFileObj = FileUtil.toFileObject(FileUtil.normalizeFile(root));
    // This can happen if the root is "ssh://<something>"
    if (rootFileObj == null || projectManager == null) {
      return null;
    }
    String res = null;
    if (projectManager.isProject(rootFileObj)) {
      try {
        Project prj = projectManager.findProject(rootFileObj);

        res = getProjectName(prj);
      } catch (Exception ex) {
        Git.LOG.log(
            Level.FINE,
            "getProjectName() file: {0} {1}",
            new Object[] {rootFileObj.getPath(), ex.toString()}); // NOI18N
      }
    }
    return res;
  }
Exemplo n.º 11
0
  /** Builds the node tree for the current session. */
  private void buildTree() {
    // Populate the root node with children.
    List<Node> list = new LinkedList<Node>();
    SessionManager sm = SessionProvider.getSessionManager();
    Session session = sm.getCurrent();

    PathManager pm = PathProvider.getPathManager(session);
    List<String> roots = pm.getSourcePath();
    if (roots != null) {
      for (String root : roots) {
        FileObject fo = FileUtil.toFileObject(new File(root));
        if (fo != null) {
          // If archive, get the root of the archive.
          fo = PathConverter.convertToRoot(fo);
        }
        Node node = new SourceRootNode(fo);
        list.add(node);
      }
    }

    if (list.size() > 0) {
      Children children = new Children.Array();
      Node[] nodes = list.toArray(new Node[list.size()]);
      children.add(nodes);
      buildRoot(children);
    } else {
      buildRoot(Children.LEAF);
    }
  }
Exemplo n.º 12
0
 private void createCatalogIfRequired(RetrieveEntry rent) {
   URI curURI = null;
   String addr = rent.getEffectiveAddress();
   try {
     // check if this is the first entry and the connection was redirected. If yes, then
     // store the URI as the original URI instead of the redirected URI
     String tempStr =
         URLResourceRetriever.resolveURL(rent.getBaseAddress(), rent.getCurrentAddress());
     if (!(new URI(tempStr).equals(new URI(addr)))) {
       addr = tempStr;
     }
   } catch (URISyntaxException ex) {
     // ignore
   }
   if (isSave2SingleFolder()) {
     if (!rent.getCurrentAddress().equals(rent.getEffectiveAddress()))
       addr = rent.getCurrentAddress();
   }
   try {
     curURI = new URI(addr);
   } catch (URISyntaxException ex) {
     // this is not supposed to happen. But if it does, then just return
     return;
   }
   FileObject fobj = null;
   try {
     fobj = FileUtil.toFileObject(FileUtil.normalizeFile(rent.getSaveFile()));
   } catch (Exception e) {
     return;
   }
   if (fobj == null) return;
   CatalogWriteModel dr = null;
   try {
     if (this.catalogFileObject == null) {
       Project project = FileOwnerQuery.getOwner(fobj);
       if (project == null) {
         // See issue #176769
         // In can happen if the file was saved outside of the project
         return;
       }
       dr = CatalogWriteModelFactory.getInstance().getCatalogWriteModelForProject(fobj);
     } else {
       dr =
           CatalogWriteModelFactory.getInstance()
               .getCatalogWriteModelForCatalogFile(this.catalogFileObject);
     }
   } catch (CatalogModelException ex) {
     // ignore this exception but return
     return;
   }
   // fobj = FileUtil.toFileObject(rent.getSaveFile());
   try {
     dr.addURI(curURI, fobj);
   } catch (Exception ex) {
     // ignore this exception but return
     ex = new Exception("Exception while writing in to catalog.", ex);
     handleException(rent, ex);
     return;
   }
 }
Exemplo n.º 13
0
 public static FileObject getWebServiceHome() {
   File websvcDir = new File(WEBSVC_HOME);
   if (!websvcDir.isFile()) {
     websvcDir.mkdirs();
   }
   return FileUtil.toFileObject(websvcDir);
 }
 /** TODO: replace with FileUtil.createFolder(File) in trunk. */
 private static FileObject createFolder(File dir) throws IOException {
   Stack stack = new Stack();
   while (!dir.exists()) {
     stack.push(dir.getName());
     dir = dir.getParentFile();
   }
   FileObject dirFO = FileUtil.toFileObject(dir);
   if (dirFO == null) {
     refreshFileSystem(dir);
     dirFO = FileUtil.toFileObject(dir);
   }
   assert dirFO != null;
   while (!stack.isEmpty()) {
     dirFO = dirFO.createFolder((String) stack.pop());
   }
   return dirFO;
 }
Exemplo n.º 15
0
 public void testDebugFix() throws Exception {
   // Track down #47012.
   Project freeform =
       ProjectManager.getDefault().findProject(FileUtil.toFileObject(file("ant.freeform")));
   assertNotNull("have project in ant/freeform", freeform);
   ActionProvider ap = freeform.getLookup().lookup(ActionProvider.class);
   assertNotNull("have ActionProvider", ap);
   FileObject actionsJava =
       FileUtil.toFileObject(
           file("ant.freeform/src/org/netbeans/modules/ant/freeform/Actions.java"));
   assertNotNull("have Actions.java", actionsJava);
   assertTrue(
       "Fix enabled on it",
       ap.isActionEnabled(
           JavaProjectConstants.COMMAND_DEBUG_FIX,
           Lookups.singleton(DataObject.find(actionsJava))));
 }
  @Override
  public Set instantiate(ProgressHandle handle) throws IOException {
    handle.start(2);
    handle.progress(
        NbBundle.getMessage(
            JavaEESamplesWizardIterator.class,
            "LBL_NewSampleProjectWizardIterator_WizardProgress_CreatingProject"),
        1);

    Set resultSet = new LinkedHashSet();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty(WizardProperties.PROJ_DIR));
    String name = (String) wiz.getProperty(WizardProperties.NAME);
    FileObject template = Templates.getTemplate(wiz);

    FileObject dir = null;
    if ("web".equals(template.getAttribute("prjType"))) {
      // Use generator from web.examples to create project with specified name
      dir = WebSampleProjectGenerator.createProjectFromTemplate(template, dirF, name);
    } else {
      // Unzip prepared project only (no way to change name of the project)
      // FIXME: should be modified to create projects with specified name (project.xml files in
      // sub-projects should be modified too)
      // FIXME: web.examples and j2ee.samples modules may be merged into one module
      createFolder(dirF);
      dir = FileUtil.toFileObject(dirF);
      unZipFile(template.getInputStream(), dir);
      WebSampleProjectGenerator.configureServer(dir);
      for (FileObject child : dir.getChildren()) {
        WebSampleProjectGenerator.configureServer(child);
      }
    }

    ProjectManager.getDefault().clearNonProjectCache();
    handle.progress(
        NbBundle.getMessage(
            JavaEESamplesWizardIterator.class,
            "LBL_NewSampleProjectWizardIterator_WizardProgress_PreparingToOpen"),
        2);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration e = dir.getFolders(true);
    while (e.hasMoreElements()) {
      FileObject subfolder = (FileObject) e.nextElement();
      if (ProjectManager.getDefault().isProject(subfolder)) {
        resultSet.add(subfolder);
      }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
      ProjectChooser.setProjectsFolder(parent);
    }

    handle.finish();
    return resultSet;
  }
 private static void refreshFileSystem(final File dir) throws FileStateInvalidException {
   File rootF = dir;
   while (rootF.getParentFile() != null) {
     rootF = rootF.getParentFile();
   }
   FileObject dirFO = FileUtil.toFileObject(rootF);
   assert dirFO != null : "At least disk roots must be mounted! " + rootF; // NOI18N
   dirFO.getFileSystem().refresh(false);
 }
 private synchronized AntProjectCookie getCookie() throws IOException {
   if (cookie == null) {
     File antFile =
         InstalledFileLocator.getDefault()
             .locate("remote-pack-defs/build.xml", "org-netbeans-lib-profiler", false); // NOI18N
     cookie = DataObject.find(FileUtil.toFileObject(antFile)).getCookie(AntProjectCookie.class);
   }
   return cookie;
 }
Exemplo n.º 19
0
  protected FileObject getTestFile(String relFilePath) {
    File wholeInputFile = new File(getDataDir(), relFilePath);
    if (!wholeInputFile.exists()) {
      NbTestCase.fail("File " + wholeInputFile + " not found.");
    }
    FileObject fo = FileUtil.toFileObject(wholeInputFile);
    assertNotNull(fo);

    return fo;
  }
 public synchronized void loadKey(File path) {
   mainKey = null;
   manager = null;
   dataObject = null;
   data = null;
   manager = new ProjectAssetManager(FileUtil.toFileObject(path).getParent());
   try {
     dataObject = DataObject.find(FileUtil.toFileObject(path));
     data = dataObject != null ? dataObject.getLookup().lookup(AssetData.class) : null;
     if (data != null) {
       ((AssetDataObject) dataObject).getLookupContents().add(manager);
       mainKey = data.getAssetKey();
     }
   } catch (DataObjectNotFoundException ex) {
     Exceptions.printStackTrace(ex);
   }
   updateProperties(mainKey);
   panel.fireChangeEvent();
 }
 @Override
 protected Map<String, ClassPath> createClassPathsForTest() {
   return Collections.singletonMap(
       PhpSourcePath.SOURCE_CP,
       ClassPathSupport.createClassPath(
           new FileObject[] {
             FileUtil.toFileObject(
                 new File(getDataDir(), "/testfiles/completion/lib/qualifiedStatic/"))
           }));
 }
  public void register(Project webApp) {
    int result = SUCCESS;

    Path target = createRegistry();

    if (target == null) {
      return;
    }
    FileObject propsFo =
        FileUtil.toFileObject(target.toFile())
            .getFileObject(SuiteConstants.SERVER_INSTANCE_WEB_APPS_PROPS);
    Properties props = new Properties();
    if (propsFo != null) {
      props = BaseUtil.loadProperties(propsFo);
      try {
        propsFo.delete();
      } catch (IOException ex) {
        LOG.log(Level.INFO, ex.getMessage());
      }
    }

    WebModule wm = WebModule.getWebModule(webApp.getProjectDirectory());

    String cp = wm.getContextPath();

    if (cp != null) {
      props.setProperty(cp, webApp.getProjectDirectory().getPath());
    } else {
      result = CONTEXTPATH_NOT_FOUND;
    }
    if (result == SUCCESS) {
      BaseUtil.storeProperties(
          props,
          FileUtil.toFileObject(target.toFile()),
          SuiteConstants.SERVER_INSTANCE_WEB_APPS_PROPS);
      String uri = SuiteManager.getManager(serverInstance).getUri();
      SuiteNotifier sn =
          SuiteManager.getServerSuiteProject(uri).getLookup().lookup(SuiteNotifier.class);
      sn.childrenChanged(this, webApp);
    }
    return;
  }
  private FileObject getArchivedFile(FileObject fileObject) {
    // ZIP and JAR archives
    if (FileUtil.isArchiveFile(fileObject)) {
      try {
        fileObject = FileUtil.getArchiveRoot(fileObject).getChildren()[0];
      } catch (Exception e) {
        throw new RuntimeException(
            "The archive can't be opened, be sure it has no password and contains a single file, without folders");
      }
    } else { // GZ or BZIP2 archives
      boolean isGz = fileObject.getExt().equalsIgnoreCase("gz");
      boolean isBzip = fileObject.getExt().equalsIgnoreCase("bz2");
      if (isGz || isBzip) {
        try {
          String[] splittedFileName = fileObject.getName().split("\\.");
          if (splittedFileName.length < 2) {
            return fileObject;
          }

          String fileExt1 = splittedFileName[splittedFileName.length - 1];
          String fileExt2 = splittedFileName[splittedFileName.length - 2];

          File tempFile = null;
          if (fileExt1.equalsIgnoreCase("tar")) {
            String fname = fileObject.getName().replaceAll("\\.tar$", "");
            fname = fname.replace(fileExt2, "");
            tempFile = File.createTempFile(fname, "." + fileExt2);
            // Untar & unzip
            if (isGz) {
              tempFile = getGzFile(fileObject, tempFile, true);
            } else {
              tempFile = getBzipFile(fileObject, tempFile, true);
            }
          } else {
            String fname = fileObject.getName();
            fname = fname.replace(fileExt1, "");
            tempFile = File.createTempFile(fname, "." + fileExt1);
            // Unzip
            if (isGz) {
              tempFile = getGzFile(fileObject, tempFile, false);
            } else {
              tempFile = getBzipFile(fileObject, tempFile, false);
            }
          }
          tempFile.deleteOnExit();
          tempFile = FileUtil.normalizeFile(tempFile);
          fileObject = FileUtil.toFileObject(tempFile);
        } catch (IOException ex) {
          Exceptions.printStackTrace(ex);
        }
      }
    }
    return fileObject;
  }
  public void refresh() {

    Properties props = getWebAppsProperties();
    props.forEach(
        (k, v) -> {
          File f = new File((String) v);
          Project p = FileOwnerQuery.getOwner(FileUtil.toFileObject(f));
          WebModule wm = WebModule.getWebModule(p.getProjectDirectory());
          String cp = wm.getContextPath();
        });
  }
 public void testRunSingleMethodDisabledWhenDoNotHaveCoSImplicit() throws Exception {
   TestFileUtils.writeFile(
       new File(getWorkDir(), "pom.xml"),
       "<project><modelVersion>4.0.0</modelVersion>"
           + "<groupId>test</groupId><artifactId>prj</artifactId>"
           + "<version>1.0</version>"
           + "<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.7</version></plugin></plugins></build>"
           + "<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.8.2</version><scope>test</scope></dependency></dependencies>"
           + "</project>");
   assertSupportsRunSingleMethod(
       ProjectManager.getDefault().findProject(FileUtil.toFileObject(getWorkDir())), false);
 }
  public FileObject getRegistry() {
    Path serverDir = Paths.get(serverInstance.getProjectDirectory().getPath());
    String root = serverDir.getRoot().toString().replaceAll(":", "_");
    if (root.startsWith("/")) {
      root = root.substring(1);
    }
    Path targetPath = serverDir.getRoot().relativize(serverDir);
    String tmp = System.getProperty("java.io.tmpdir");

    Path target = Paths.get(tmp, SuiteConstants.TMP_DIST_WEB_APPS, root, targetPath.toString());
    return FileUtil.toFileObject(target.toFile());
  }
  boolean valid(WizardDescriptor wizardDescriptor) {

    if (projectNameTextField.getText().length() == 0) {
      wizardDescriptor.putProperty(
          WIZARD_PANEL_ERROR_MESSAGE,
          org.openide.util.NbBundle.getMessage(
              SampleAppPanelVisual.class, "SampleAppPanelVisual.invalid_folder_name"));
      return false; // Display name not specified
    }
    File f = FileUtil.normalizeFile(new File(projectLocationTextField.getText()).getAbsoluteFile());
    if (!f.isDirectory()) {
      String message =
          org.openide.util.NbBundle.getMessage(
              SampleAppPanelVisual.class, "SampleAppPanelVisual.invalid_path");
      wizardDescriptor.putProperty(WIZARD_PANEL_ERROR_MESSAGE, message);
      return false;
    }
    final File destFolder =
        FileUtil.normalizeFile(new File(createdFolderTextField.getText()).getAbsoluteFile());

    File projLoc = destFolder;
    while (projLoc != null && !projLoc.exists()) {
      projLoc = projLoc.getParentFile();
    }
    if (projLoc == null || !projLoc.canWrite()) {
      wizardDescriptor.putProperty(
          WIZARD_PANEL_ERROR_MESSAGE,
          org.openide.util.NbBundle.getMessage(
              SampleAppPanelVisual.class, "SampleAppPanelVisual.folder_creation_error"));
      return false;
    }

    if (FileUtil.toFileObject(projLoc) == null) {
      String message =
          org.openide.util.NbBundle.getMessage(
              SampleAppPanelVisual.class, "SampleAppPanelVisual.invalid_path");
      wizardDescriptor.putProperty(WIZARD_PANEL_ERROR_MESSAGE, message);
      return false;
    }

    File[] kids = destFolder.listFiles();
    if (destFolder.exists() && kids != null && kids.length > 0) {
      // Folder exists and is not empty
      wizardDescriptor.putProperty(
          WIZARD_PANEL_ERROR_MESSAGE,
          org.openide.util.NbBundle.getMessage(
              SampleAppPanelVisual.class, "SampleAppPanelVisual.folder_exists"));
      return false;
    }
    wizardDescriptor.putProperty(WIZARD_PANEL_ERROR_MESSAGE, "");
    return true;
  }
 public ALT_SeqResizing15Test(String name) {
   super(name);
   try {
     className = this.getClass().getName();
     className = className.substring(className.lastIndexOf('.') + 1, className.length());
     startingFormFile =
         FileUtil.toFileObject(
             new File(url.getFile() + goldenFilesPath + className + "-StartingForm.form")
                 .getCanonicalFile());
   } catch (IOException ioe) {
     fail(ioe.toString());
   }
 }
 public void testRunSingleMethodEnabledForUnusualJUnitScope() throws Exception {
   TestFileUtils.writeFile(
       new File(getWorkDir(), "pom.xml"),
       "<project><modelVersion>4.0.0</modelVersion>"
           + "<groupId>test</groupId><artifactId>prj</artifactId>"
           + "<version>1.0</version>"
           + "<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.8</version></plugin></plugins></build>"
           + "<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.8.2</version></dependency></dependencies>"
           + "<properties><netbeans.compile.on.save>none</netbeans.compile.on.save></properties>"
           + "</project>");
   assertSupportsRunSingleMethod(
       ProjectManager.getDefault().findProject(FileUtil.toFileObject(getWorkDir())), true);
 }
Exemplo n.º 30
0
  @Override
  protected void setUp() throws Exception {
    dataRootDir = getWorkDir();
    dataRootDir.mkdirs();
    File userdir = new File(dataRootDir + "userdir");
    userdir.mkdirs();
    System.setProperty("netbeans.user", userdir.getAbsolutePath());

    FileObject fo = FileUtil.toFileObject(getWorkDir());
    MockServices.setServices(DeleteCreateTestAnnotationProvider.class);
    // interceptor init
    DeleteCreateTestAnnotationProvider.instance.init();
  }