org.eclipse.xtext.util.Files Java Examples
The following examples show how to use
org.eclipse.xtext.util.Files.
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 |
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: CliWizardIntegrationTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * Use this main method to update the expectations to whatever the wizard * currently generates */ public static void main(String[] args) { try { CliProjectsCreator creator = CliWizardIntegrationTest.newProjectCreator(); for (WizardConfiguration config : CliWizardIntegrationTest.projectConfigs) { File targetLocation = new File("testdata/wizard-expectations", config.getBaseName()); targetLocation.mkdirs(); Files.sweepFolder(targetLocation); config.setRootLocation(targetLocation.getPath()); creator.createProjects(config); InputOutput.println("Updating expectations for " + config.getBaseName()); } } catch (FileNotFoundException e) { throw Exceptions.sneakyThrow(e); } }
Example #3
Source File: WorkspaceManagerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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 #4
Source File: MultiProjectTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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 #5
Source File: TestBatchCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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 #6
Source File: TestBatchCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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 #7
Source File: AbstractSmokeTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws Exception { int i = 0; // TODO sz: investigate how to speed things up here (parallelism)? smokeTestModels = Lists.newArrayList(); while (true) { String location = SmokeTest.class.getPackage().getName().replace('.', '/') + "/Case_" + i + ".xtend.smoke"; URL resource = getClass().getClassLoader().getResource(location); if (resource == null) resource = getClass().getClassLoader().getResource("/" + location); if (resource == null) break; final InputStream resourceAsStream = resource.openStream(); String string = Files.readStreamIntoString(resourceAsStream); smokeTestModels.add(string); i++; } }
Example #8
Source File: OnTheFlyJavaCompiler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
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 #9
Source File: SourceBasedJdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassAnnotationValue_08() throws Exception { IJavaProject project = projectProvider.getJavaProject(null); String typeName = EmptyAbstractClass.class.getName(); IFile javaFile = (IFile) project.getProject().findMember(new Path("src/" + typeName.replace('.', '/') + ".java")); assertNotNull(javaFile); String content = Files.readStreamIntoString(javaFile.getContents()); try { String newContent = content.replace( "public abstract ", "@TestAnnotation( classArray = { String.class, DoesNotExist.class, String.class } ) public abstract "); javaFile.setContents(new StringInputStream(newContent), IResource.NONE, new NullProgressMonitor()); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); List<JvmAnnotationReference> annotations = type.getAnnotations(); assertEquals(1, annotations.size()); JvmAnnotationReference annotation = annotations.get(0); assertEquals(1, annotation.getExplicitValues().size()); JvmAnnotationValue value = annotation.getExplicitValues().get(0); assertTrue(value instanceof JvmTypeAnnotationValue); List<JvmTypeReference> typeLiterals = ((JvmTypeAnnotationValue) value).getValues(); assertEquals(2, typeLiterals.size()); } finally { javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor()); } }
Example #10
Source File: SourceBasedJdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassAnnotationValue_07() throws Exception { IJavaProject project = projectProvider.getJavaProject(null); String typeName = EmptyAbstractClass.class.getName(); IFile javaFile = (IFile) project.getProject().findMember(new Path("src/" + typeName.replace('.', '/') + ".java")); assertNotNull(javaFile); String content = Files.readStreamIntoString(javaFile.getContents()); try { String newContent = content.replace( "public abstract ", "@SimpleAnnotation( type = DoesNotExist.class ) public abstract "); javaFile.setContents(new StringInputStream(newContent), IResource.NONE, new NullProgressMonitor()); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); List<JvmAnnotationReference> annotations = type.getAnnotations(); assertEquals(1, annotations.size()); JvmAnnotationReference annotation = annotations.get(0); assertEquals(1, annotation.getExplicitValues().size()); JvmAnnotationValue value = annotation.getExplicitValues().get(0); assertTrue(value instanceof JvmTypeAnnotationValue); assertTrue(((JvmTypeAnnotationValue) value).getValues().isEmpty()); } finally { javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor()); } }
Example #11
Source File: SourceBasedJdtTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testClassAnnotationValue_09() throws Exception { IJavaProject project = projectProvider.getJavaProject(null); String typeName = EmptyAbstractClass.class.getName(); IFile javaFile = (IFile) project.getProject().findMember(new Path("src/" + typeName.replace('.', '/') + ".java")); assertNotNull(javaFile); String content = Files.readStreamIntoString(javaFile.getContents()); try { String newContent = content.replace( "public abstract ", "@TestAnnotation( classArray = ) public abstract "); javaFile.setContents(new StringInputStream(newContent), IResource.NONE, new NullProgressMonitor()); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); List<JvmAnnotationReference> annotations = type.getAnnotations(); assertEquals(1, annotations.size()); JvmAnnotationReference annotation = annotations.get(0); assertEquals(1, annotation.getExplicitValues().size()); JvmAnnotationValue value = annotation.getExplicitValues().get(0); assertTrue(value instanceof JvmTypeAnnotationValue); List<JvmTypeReference> typeLiterals = ((JvmTypeAnnotationValue) value).getValues(); assertEquals(0, typeLiterals.size()); } finally { javaFile.setContents(new StringInputStream(content), IResource.NONE, new NullProgressMonitor()); } }
Example #12
Source File: TestEclipseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@After public void tearDown() throws FileNotFoundException { if (outputClassDirectory != null && outputClassDirectory.exists()) { assertTrue("Unable to delete test directory: " + outputClassDirectory.getAbsolutePath(), Files.sweepFolder(outputClassDirectory)); } }
Example #13
Source File: SarlBatchCompiler.java From sarl with Apache License 2.0 | 5 votes |
/** 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; } }
Example #14
Source File: CliWizardIntegrationTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private GeneratedFile toGeneratedFile(File file, String relativePath) { try { String content; if (file.isDirectory()) { content = ""; } else { content = com.google.common.io.Files.asCharSource(file, config.getEncoding()).read(); } return new GeneratedFile(relativePath, content); } catch (IOException e) { throw Exceptions.sneakyThrow(e); } }
Example #15
Source File: OnTheFlyJavaCompiler.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected File createTempDir() { if (temporaryFolder != null && temporaryFolder.isInitialized()) { try { return temporaryFolder.newFolder(); } catch (IOException e) { throw new RuntimeIOException(e); } } return com.google.common.io.Files.createTempDir(); }
Example #16
Source File: AbstractLanguageServerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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 #17
Source File: WorkspaceManagerTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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 #18
Source File: StandaloneBuilderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@After public void cleanup() throws IOException { deleteFolder("src-gen"); deleteFolder("src2-gen"); if (TMP_DIR.exists()) { Files.sweepFolder(TMP_DIR); TMP_DIR.delete(); } }
Example #19
Source File: StandaloneBuilderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private void deleteFolder(String projectRelativePath) throws FileNotFoundException { File folder = getFile(projectRelativePath); if (folder.exists()) { Files.sweepFolder(folder); folder.delete(); } }
Example #20
Source File: XtendBatchCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
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 #21
Source File: TestBatchCompiler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private String getContents(final String fileName) { try { File _file = new File(fileName); return com.google.common.io.Files.asCharSource(_file, Charsets.UTF_8).read(); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #22
Source File: GeneratorUtil.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 #23
Source File: OnTheFlyJavaCompiler.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected File createTempDir() { if (temporaryFolder != null && temporaryFolder.isInitialized()) { try { return temporaryFolder.newFolder(); } catch (IOException e) { throw new RuntimeIOException(e); } } return com.google.common.io.Files.createTempDir(); }
Example #24
Source File: TestEclipseCompiler.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@After public void tearDown() throws FileNotFoundException { if (outputClassDirectory != null && outputClassDirectory.exists()) { assertTrue("Unable to delete test directory: " + outputClassDirectory.getAbsolutePath(), Files.sweepFolder(outputClassDirectory)); } }
Example #25
Source File: StandaloneBuilderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void deleteFolder(String projectRelativePath) throws FileNotFoundException { File folder = getFile(projectRelativePath); if (folder.exists()) { Files.sweepFolder(folder); folder.delete(); } }
Example #26
Source File: StandaloneBuilderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@After public void cleanup() throws IOException { deleteFolder("src-gen"); deleteFolder("src2-gen"); if (TMP_DIR.exists()) { Files.sweepFolder(TMP_DIR); TMP_DIR.delete(); } }
Example #27
Source File: DerivedSourceView.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override protected String computeInput(IWorkbenchPartSelection workbenchPartSelection) { openEditorAction.setInputFile(null); openEditorAction.setSelectedRegion(null); IEclipseTrace trace = traceInformation.getTraceToTarget(getEditorResource(workbenchPartSelection)); if (trace != null) { if (workbenchPartSelection instanceof DerivedSourceSelection) { DerivedSourceSelection derivedSourceSelection = (DerivedSourceSelection) workbenchPartSelection; selectedSource = derivedSourceSelection.getStorage(); } else { derivedSources = Sets.newHashSet(); TextRegion localRegion = mapTextRegion(workbenchPartSelection); Iterable<IStorage> transform = Iterables.filter(transform(trace.getAllAssociatedLocations(localRegion), new Function<ILocationInEclipseResource, IStorage>() { @Override public IStorage apply(ILocationInEclipseResource input) { return input.getPlatformResource(); } }), Predicates.notNull()); addAll(derivedSources, transform); ILocationInEclipseResource bestAssociatedLocation = trace.getBestAssociatedLocation(localRegion); if (bestAssociatedLocation != null) { selectedSource = bestAssociatedLocation.getPlatformResource(); } else if (!derivedSources.isEmpty()) { selectedSource = derivedSources.iterator().next(); } } } IFile file = getSelectedFile(); if (file != null) { try { file.refreshLocal(1, new NullProgressMonitor()); if (file.exists()) { openEditorAction.setInputFile(file); return Files.readStreamIntoString(file.getContents()); } } catch (CoreException e) { throw new WrappedRuntimeException(e); } } return null; }