public void testGeneratedSources() throws Exception { // #187595 TestFileUtils.writeFile( d, "pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>grp</groupId>" + "<artifactId>art</artifactId>" + "<packaging>jar</packaging>" + "<version>0</version>" + "</project>"); FileObject src = FileUtil.createFolder(d, "src/main/java"); FileObject gsrc = FileUtil.createFolder(d, "target/generated-sources/xjc"); gsrc.createData("Whatever.class"); FileObject tsrc = FileUtil.createFolder(d, "src/test/java"); FileObject gtsrc = FileUtil.createFolder(d, "target/generated-test-sources/jaxb"); gtsrc.createData("Whatever.class"); assertEquals( Arrays.asList(src, gsrc), Arrays.asList( SourceForBinaryQuery.findSourceRoots(new URL(d.toURL(), "target/classes/")) .getRoots())); assertEquals( Arrays.asList(tsrc, gtsrc), Arrays.asList( SourceForBinaryQuery.findSourceRoots(new URL(d.toURL(), "target/test-classes/")) .getRoots())); }
private static void unZipFile(InputStream source, FileObject projectRoot) throws IOException { try { ZipInputStream str = new ZipInputStream(source); ZipEntry entry; while ((entry = str.getNextEntry()) != null) { if (entry.isDirectory()) { FileUtil.createFolder(projectRoot, entry.getName()); } else { FileObject fo = FileUtil.createData(projectRoot, entry.getName()); FileLock lock = fo.lock(); try { OutputStream out = fo.getOutputStream(lock); try { FileUtil.copy(str, out); } finally { out.close(); } } finally { lock.releaseLock(); } } } } finally { source.close(); } }
private static void unZipFile(InputStream source, FileObject projectRoot, WizardDescriptor wiz) throws IOException { try { ZipInputStream str = new ZipInputStream(source); ZipEntry entry; while ((entry = str.getNextEntry()) != null) { if (entry.isDirectory()) { FileUtil.createFolder(projectRoot, entry.getName()); } else { FileObject fo = FileUtil.createData(projectRoot, entry.getName()); if ("nbproject/project.xml".equals(entry.getName())) { // Special handling for setting name of Ant-based projects; customize as needed: filterProjectXML(fo, str, projectRoot.getName()); } // if build.xml has been found replace its content with provided values else if ("build.xml".equals(entry.getName())) { processBuildXML(fo, str, wiz); } else if ("nbproject/project.properties".equals(entry.getName())) { processProjectProperties(fo, str, wiz, projectRoot.getName()); } else { writeFile(str, fo); } } } } finally { source.close(); } }
public void testPreferencesEvents() throws Exception { storage.toFolder(true); FileUtil.getConfigRoot().addRecursiveListener(new FileListener()); pref.addNodeChangeListener(new NodeListener()); String newPath = "a/b/c"; String[] paths = newPath.split("/"); FileObject fo = null; FileObject fo0 = null; for (int i = 0; i < paths.length; i++) { String path = paths[i]; fo = FileUtil.createFolder((fo == null) ? FileUtil.getConfigRoot() : fo, path); if (i == 0) { fo0 = fo; } nodeAddedEvent.await(); assertEquals("Missing node added event", 0, nodeAddedEvent.getCount()); nodeAddedEvent = new CountDownLatch(1); Preferences pref2 = pref.node(fo.getPath()); pref2.addNodeChangeListener(new NodeListener()); } FileObject fo1 = FileUtil.createData(fo, "a.properties"); nodeAddedEvent.await(); assertEquals("Missing node added event", 0, nodeAddedEvent.getCount()); nodeRemovedEvent = new CountDownLatch(paths.length + 1); fo0.delete(); nodeRemovedEvent.await(); assertEquals("Missing node removed event", 0, nodeRemovedEvent.getCount()); }
public Path createRegistry() { 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()); File file = target.toFile(); if (!file.exists()) { try { FileUtil.createFolder(file); } catch (IOException ex) { // result = CREATE_FOLDER_ERROR; target = null; LOG.log(Level.INFO, ex.getMessage()); } } return target; }
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); }
/** 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); }
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)); }
void store(WizardDescriptor settings) { // settings.putProperty(WizardProperties.JSF_FOLDER, jsfFolder.getText()); String pkg = getPackage(); settings.putProperty(WizardProperties.JPA_CONTROLLER_PACKAGE, pkg); // settings.putProperty(WizardProperties.AJAXIFY_JSF_CRUD, // Boolean.valueOf(ajaxifyCheckbox.isSelected())); try { FileObject fo = getLocationValue().getRootFolder(); String pkgSlashes = pkg.replace('.', '/'); FileObject targetFolder = fo.getFileObject(pkgSlashes); if (targetFolder == null) { targetFolder = FileUtil.createFolder(fo, pkgSlashes); } Templates.setTargetFolder(settings, targetFolder); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
private void createFile() { if (result != null && result.indexOf('\\') == -1) { // NOI18N if (!targetFolder.getPrimaryFile().canWrite()) { return; } DataObject dObj = null; try { FileObject fo = type == TYPE_FILE ? FileUtil.createData(targetFolder.getPrimaryFile(), result) : FileUtil.createFolder(targetFolder.getPrimaryFile(), result); if (fo != null) { dObj = DataObject.find(fo); } } catch (DataObjectNotFoundException e) { // No data object no open } catch (IOException e) { // XXX } if (result != null) { // handle new template in SystemFileSystem DataObject rootDO = findTemplate("/Templates"); // NOI18N if (rootDO != null && dObj != null) { if (FileUtil.isParentOf(rootDO.getPrimaryFile(), dObj.getPrimaryFile())) { try { dObj.setTemplate(true); } catch (IOException e) { // can ignore } } } } if (dObj != null) { ProjectUtilities.openAndSelectNewObject(dObj); } } }
private static void unZipFile(InputStream source, FileObject projectRoot) throws IOException { try { ZipInputStream str = new ZipInputStream(source); ZipEntry entry; while ((entry = str.getNextEntry()) != null) { if (entry.isDirectory()) { FileUtil.createFolder(projectRoot, entry.getName()); } else { FileObject fo = FileUtil.createData(projectRoot, entry.getName()); if ("nbproject/project.xml".equals(entry.getName())) { // Special handling for setting name of Ant-based projects; customize as needed: filterProjectXML(fo, str, projectRoot.getName()); } else { writeFile(str, fo); } } } } finally { source.close(); } }
private void doAnalysis() { if (project != null) { if (output.getIterations() != null) { if (!output.getIterations().isEmpty()) { numIterations = Integer.parseInt(output.getIterations()); } } else { numIterations = NO_OF_ITERATIONS; } if (output.getOutputPath() != null) { String[] nlsprogressResult = null; String outputPath = project.getResultsFolder(true) + File.separator + output.getOutputPath(); File outputFolder = new File(outputPath); if (outputFolder.exists()) { resultsfolder = FileUtil.toFileObject(outputFolder); if (resultsfolder.getChildren().length > 0) { try { resultsfolder = FileUtil.createFolder( resultsfolder.getParent(), FileUtil.findFreeFolderName( resultsfolder.getParent(), resultsfolder.getName())); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } else { try { FileUtil.createFolder(outputFolder); resultsfolder = outputFolder.exists() ? FileUtil.toFileObject(outputFolder) : null; } catch (IOException ex) { Exceptions.printStackTrace(ex); } } datasets = getDatasets(datasetContainer); modelCalls.add(getModelCall(modelReference, 0)); fitModelCall = getFitModelCall(datasets, modelCalls, modelDifferences, output, numIterations); if (isValidAnalysis(datasets, modelReference)) { timpcontroller = Lookup.getDefault().lookup(TimpControllerInterface.class); if (timpcontroller != null) { results = timpcontroller.runAnalysis(datasets, modelCalls, fitModelCall); nlsprogressResult = timpcontroller.getStringArray( TimpControllerInterface.NAME_OF_RESULT_OBJECT + "$nlsprogress"); } } else { // TODO: CoreErrorMessages warning return; } if (results != null) { writeResults(results, modelReference, nlsprogressResult); } else { try { writeSummary( resultsfolder, FileUtil.findFreeFileName( resultsfolder, resultsfolder.getName() + "_errorlog", "summary")); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } timpcontroller.cleanup(); } } }
@Override public FileObject getCacheDirectory() throws IOException { return FileUtil.createFolder(helper.getProjectDirectory(), CACHE_PATH); }
public void testForeignClassBundler() throws Exception { // #155091 and deps TestFileUtils.writeFile( d, "a/pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>grp</groupId>" + "<artifactId>art</artifactId>" + "<packaging>jar</packaging>" + "<version>0</version>" + "</project>"); FileObject src = FileUtil.createFolder(d, "a/src/main/java"); File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile(); File art = new File( repo, "grp" + File.separator + "art" + File.separator + "0" + File.separator + "art-0.jar"); URL root = FileUtil.getArchiveRoot(Utilities.toURI(art).toURL()); Project p = ProjectManager.getDefault().findProject(d.getFileObject("a")); FileOwnerQuery.markExternalOwner( Utilities.toURI(art), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); MavenFileOwnerQueryImpl.getInstance() .registerCoordinates("grp", "art", "0", d.getFileObject("a").toURL()); SourceForBinaryQuery.Result2 r = SourceForBinaryQuery.findSourceRoots2(root); assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots())); assertTrue(r.preferSources()); TestFileUtils.writeFile( d, "b/pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>grp</groupId>" + "<artifactId>art</artifactId>" + "<packaging>war</packaging>" + "<version>0</version>" + "</project>"); src = FileUtil.createFolder(d, "b/src/main/java"); art = new File( repo, "grp" + File.separator + "art" + File.separator + "0" + File.separator + "art-0.jar"); FileOwnerQuery.markExternalOwner( Utilities.toURI(art), ProjectManager.getDefault().findProject(d.getFileObject("b")), FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); root = FileUtil.getArchiveRoot(Utilities.toURI(art).toURL()); p = ProjectManager.getDefault().findProject(d.getFileObject("b")); FileOwnerQuery.markExternalOwner( Utilities.toURI(art), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); MavenFileOwnerQueryImpl.getInstance() .registerCoordinates("grp", "art", "0", d.getFileObject("b").toURL()); r = SourceForBinaryQuery.findSourceRoots2(root); assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots())); assertFalse(r.preferSources()); // 215242 assert that output dir does prefer sources r = SourceForBinaryQuery.findSourceRoots2(new URL(d.toURL(), "b/target/classes/")); assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots())); assertTrue(r.preferSources()); }
public int unregister(Project webApp) { int result = SUCCESS; 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()); File file = target.toFile(); if (!file.exists()) { try { FileUtil.createFolder(file); } catch (IOException ex) { result = CREATE_FOLDER_ERROR; LOG.log(Level.INFO, ex.getMessage()); } } 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) { result = CREATE_FOLDER_ERROR; LOG.log(Level.INFO, ex.getMessage()); } } WebModule wm = WebModule.getWebModule(webApp.getProjectDirectory()); String cp = wm.getContextPath(); if (cp != null) { props.remove(cp); FileObject targetFo = FileUtil.toFileObject(target.toFile()); } 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(); Project suite = SuiteManager.getServerSuiteProject(uri); if (suite == null) { result = NOT_A_SUITE; } else { SuiteNotifier sn = suite.getLookup().lookup(SuiteNotifier.class); sn.childrenChanged(this, webApp); } } return result; }