Java Code Examples for org.eclipse.xtext.util.Files#cleanFolder()

The following examples show how to use org.eclipse.xtext.util.Files#cleanFolder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnTheFlyJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void cleanUpTmpFolder(File tempDir) {
	if (temporaryFolder == null || !temporaryFolder.isInitialized()) {
		try {
			tempDir.deleteOnExit();
			// Classloader needs .class files to lazy load an anonymous non static classes
			Files.cleanFolder(tempDir, new FileFilter() {
				@Override
				public boolean accept(File pathname) {
					boolean isClass = pathname.getName().endsWith(".class");
					if(isClass) {
						pathname.deleteOnExit();
					}
					return !isClass;
				}
			}, true, true);
		} catch (FileNotFoundException e) {
			// ignore
		}
	}
}
 
Example 2
Source File: OnTheFlyJavaCompiler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void cleanUpTmpFolder(File tempDir) {
	if (temporaryFolder == null || !temporaryFolder.isInitialized()) {
		try {
			tempDir.deleteOnExit();
			// Classloader needs .class files to lazy load an anonymous non static classes
			Files.cleanFolder(tempDir, new FileFilter() {
				@Override
				public boolean accept(File pathname) {
					boolean isClass = pathname.getName().endsWith(".class");
					if(isClass) {
						pathname.deleteOnExit();
					}
					return !isClass;
				}
			}, true, true);
		} catch (FileNotFoundException e) {
			// ignore
		}
	}
}
 
Example 3
Source File: TestBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void onSetup() {
  try {
    this.batchCompiler.setSourcePath(TestBatchCompiler.XTEND_SRC_DIRECTORY);
    this.batchCompiler.setOutputPath(TestBatchCompiler.OUTPUT_DIRECTORY);
    this.batchCompiler.setDeleteTempDirectory(true);
    this.batchCompiler.setUseCurrentClassLoaderAsParent(true);
    this.batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader());
    new File(TestBatchCompiler.OUTPUT_DIRECTORY).mkdir();
    File _file = new File(TestBatchCompiler.OUTPUT_DIRECTORY);
    Files.cleanFolder(_file, null, true, false);
    new File(TestBatchCompiler.OUTPUT_DIRECTORY_WITH_SPACES).mkdir();
    File _file_1 = new File(TestBatchCompiler.OUTPUT_DIRECTORY_WITH_SPACES);
    Files.cleanFolder(_file_1, null, true, false);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: TestBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@After
public void onTearDown() {
  try {
    File _file = new File(TestBatchCompiler.OUTPUT_DIRECTORY);
    Files.cleanFolder(_file, null, true, true);
    File _file_1 = new File(TestBatchCompiler.OUTPUT_DIRECTORY_WITH_SPACES);
    Files.cleanFolder(_file_1, null, true, true);
    boolean _exists = new File(TestBatchCompiler.TEMP_DIRECTORY).exists();
    if (_exists) {
      File _file_2 = new File(TestBatchCompiler.TEMP_DIRECTORY);
      Files.cleanFolder(_file_2, null, true, true);
    }
    boolean _exists_1 = new File(TestBatchCompiler.TEMP_DIRECTORY_WITH_SPACES).exists();
    if (_exists_1) {
      File _file_3 = new File(TestBatchCompiler.TEMP_DIRECTORY_WITH_SPACES);
      Files.cleanFolder(_file_3, null, true, true);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: MultiProjectTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected File getRoot(final String path) {
  try {
    File _xblockexpression = null;
    {
      final File root = new File(path);
      boolean _mkdirs = root.mkdirs();
      boolean _not = (!_mkdirs);
      if (_not) {
        Files.cleanFolder(root, null, true, false);
      }
      root.deleteOnExit();
      _xblockexpression = root;
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: WorkspaceManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setup() {
  try {
    ServerModule _serverModule = new ServerModule();
    final Injector injector = Guice.createInjector(_serverModule);
    injector.injectMembers(this);
    File _file = new File("./test-data/test-project");
    this.root = _file;
    boolean _mkdirs = this.root.mkdirs();
    boolean _not = (!_mkdirs);
    if (_not) {
      Files.cleanFolder(this.root, null, true, false);
    }
    this.root.deleteOnExit();
    final Procedure2<URI, Iterable<Issue>> _function = (URI $0, Iterable<Issue> $1) -> {
      this.diagnostics.put($0, IterableExtensions.<Issue>toList($1));
    };
    this.workspaceManger.initialize(this.uriExtensions.withEmptyAuthority(URI.createFileURI(this.root.getAbsolutePath())), _function, null);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: GeneratorUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public static void cleanFolder(String srcGenPath) throws FileNotFoundException {
	File f = new File(srcGenPath);
	if (!f.exists())
		throw new FileNotFoundException(srcGenPath + " " + f.getAbsolutePath());
	log.info("Cleaning folder " + f.getPath());
	Files.cleanFolder(f, new FileFilter() {
		private final Collection<String> excludes = new HashSet<String>(Arrays.asList(defaultExcludes));
		@Override
		public boolean accept(File pathname) {
			return !excludes.contains(pathname.getName());
		}
	}, false, false);
}
 
Example 8
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected static boolean cleanFolder(File parentFolder, FileFilter filter, boolean continueOnError,
		boolean deleteParentFolder) {
	try {
		log.debug("Cleaning folder " + parentFolder.toString());
		return Files.cleanFolder(parentFolder, null, continueOnError, deleteParentFolder);
	} catch (FileNotFoundException e) {
		return true;
	}
}
 
Example 9
Source File: WorkspaceManagerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@After
public void cleanup() {
  try {
    boolean _exists = this.root.exists();
    if (_exists) {
      Files.cleanFolder(this.root, null, true, true);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@After
@AfterEach
public void cleanup() {
  try {
    boolean _exists = this.root.exists();
    if (_exists) {
      Files.cleanFolder(this.root, null, true, true);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source File: SarlBatchCompiler.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Clean the folders.
 *
 * @param parentFolder the parent folder.
 * @param filter the file filter for the file to remove.
 * @return the success status.
 */
protected boolean cleanFolder(File parentFolder, FileFilter filter) {
	try {
		if (getLogger().isLoggable(Level.FINEST)) {
			getLogger().finest(MessageFormat.format(Messages.SarlBatchCompiler_9, parentFolder.toString()));
		}
		return Files.cleanFolder(parentFolder, null, true, true);
	} catch (FileNotFoundException e) {
		return true;
	}
}