Java Code Examples for org.eclipse.core.runtime.FileLocator#toFileURL()
The following examples show how to use
org.eclipse.core.runtime.FileLocator#toFileURL() .
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: DocumentMigrationIT.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Test public void testDocumentMigrationTypeFrom63() throws IOException, InvocationTargetException, InterruptedException { final ImportBosArchiveOperation op = new ImportBosArchiveOperation(repositoryAccessor); final URL fileURL1 = FileLocator .toFileURL(DocumentMigrationIT.class.getResource("DiagramToTestDocumentTypeMigration-1.0.bos")); op.setArchiveFile(FileLocator.toFileURL(fileURL1).getFile()); op.setCurrentRepository(repositoryAccessor.getCurrentRepository()); op.run(Repository.NULL_PROGRESS_MONITOR); final DiagramRepositoryStore store = repositoryAccessor.getRepositoryStore(DiagramRepositoryStore.class); final MainProcess mainProcess = store.getChild("DiagramToTestDocumentTypeMigration-1.0.proc", true).getContent(); final Pool pool = (Pool) mainProcess.getElements().get(0); for (final Document document : pool.getDocuments()) { final String documentName = document.getName(); if ("documentWithExternalCheckedWithoutInitialContent".equals(documentName) || "documentWithInternalCheckedWithoutInitialContent".equals(documentName)) { Assertions.assertThat(document.getDocumentType()).isEqualTo(DocumentType.NONE); } else if ("documentWithExternalCheckedWithInitialContent".equals(documentName)) { Assertions.assertThat(document.getDocumentType()).isEqualTo(DocumentType.EXTERNAL); Assertions.assertThat(document.getUrl().getContent()).isEqualTo("http://test.demo"); } else if ("documentWithInternalCheckedWithInitialContent".equals(documentName)) { Assertions.assertThat(document.getDocumentType()).isEqualTo(DocumentType.INTERNAL); Assertions.assertThat(document.getDefaultValueIdOfDocumentStore()).isNotEmpty(); } } }
Example 2
Source File: TestTokenDispatcher.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
private ProcessDiagramEditor importBos(final String processResourceName) throws IOException, InvocationTargetException, InterruptedException { final ImportBosArchiveOperation op = new ImportBosArchiveOperation(repositoryAccessor); final URL fileURL = FileLocator.toFileURL(TestTokenDispatcher.class.getResource(processResourceName)); op.setArchiveFile(FileLocator.toFileURL(fileURL).getFile()); op.setCurrentRepository(repositoryAccessor.getCurrentRepository()); op.run(new NullProgressMonitor()); ProcessDiagramEditor processEditor = null; for (final IRepositoryFileStore f : op.getFileStoresToOpen()) { final IWorkbenchPart iWorkbenchPart = f.open(); if (iWorkbenchPart instanceof ProcessDiagramEditor) { processEditor = (ProcessDiagramEditor) iWorkbenchPart; } } return processEditor; }
Example 3
Source File: WorkspacePreferences.java From gama with GNU General Public License v3.0 | 6 votes |
public static String getCurrentGamaStampString() { String gamaStamp = null; try { final URL tmpURL = new URL("platform:/plugin/msi.gama.models/models/"); final URL resolvedFileURL = FileLocator.toFileURL(tmpURL); // We need to use the 3-arg constructor of URI in order to properly escape file system chars final URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null).normalize(); final File modelsRep = new File(resolvedURI); // loading file from URL Path is not a good idea. There are some bugs // File modelsRep = new File(urlRep.getPath()); final long time = modelsRep.lastModified(); gamaStamp = ".built_in_models_" + time; DEBUG.OUT( ">GAMA version " + Platform.getProduct().getDefiningBundle().getVersion().toString() + " loading..."); DEBUG.OUT(">GAMA models library version: " + gamaStamp); } catch (final IOException | URISyntaxException e) { e.printStackTrace(); } return gamaStamp; }
Example 4
Source File: BPMNImportExportTest.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
protected void checkGraphic(final String fileName, final MainProcess mainProcess) throws IOException { final URL bpmnResource = FileLocator.toFileURL(BPMNImportExportTest.class.getResource(fileName)); final ResourceSet resourceSet1 = new ResourceSetImpl(); final Resource resource1 = resourceSet1.createResource(BPMNTestUtil.toEMFURI(new File(bpmnResource.getFile()))); resource1.load(Collections.emptyMap()); new File(resource1.getURI().toFileString()).deleteOnExit(); final Diagram diagramFor = ModelHelper.getDiagramFor(mainProcess); DiagramEditPart dep; try { dep = OffscreenEditPartFactory.getInstance().createDiagramEditPart(diagramFor, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); } catch (final Exception ex) { dep = OffscreenEditPartFactory.getInstance().createDiagramEditPart(diagramFor, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); } final MainProcessEditPart mped = (MainProcessEditPart) dep; checkAllEditPartsAreVisible(mped); }
Example 5
Source File: TestProcessZoo.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Test public void testProcesses() throws Throwable { int foundProcesses = 0; final List<URL> entries = getEntries(); for (URL url : entries) { url = FileLocator.toFileURL(url); try { applyTestsOnProcess(url); } catch (final Exception ex) { BonitaStudioLog.error(ex); throw new Exception("Error on file: " + url.toString(), ex); } foundProcesses++; } assertNotSame("No process was tested", 0, foundProcesses); }
Example 6
Source File: EditorUtil.java From birt with Eclipse Public License 1.0 | 6 votes |
public static File convertToFile( URL url ) throws IOException { if ( url == null ) { throw new IOException( Messages.getString( "ResourceAction.ConvertToFile.URLIsNull" ) ); //$NON-NLS-1$ } URL fileURL = FileLocator.toFileURL( url ); IPath path = new Path( ( fileURL ).getPath( ) ); String ref = fileURL.getRef( ); String fullPath = path.toFile( ).getAbsolutePath( ); if ( ref != null ) { ref = "#" + ref; //$NON-NLS-1$ if ( path.toString( ).endsWith( "/" ) ) //$NON-NLS-1$ { return path.append( ref ).toFile( ); } else { fullPath += ref; } } return new File( fullPath ); }
Example 7
Source File: AbstractAcuteTest.java From aCute with Eclipse Public License 2.0 | 6 votes |
/** * * @param projectName the name that will be used as prefix for the project, and that will be used to find * the content of the project from the plugin "projects" folder * @throws IOException * @throws CoreException * @throws InterruptedException */ protected IProject provisionProject(String projectName) throws IOException, CoreException, InterruptedException { URL url = FileLocator.find(Platform.getBundle("org.eclipse.acute.tests"), Path.fromPortableString("projects/" + projectName), Collections.emptyMap()); url = FileLocator.toFileURL(url); File folder = new File(url.getFile()); if (folder != null && folder.exists()) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName + "_" + getClass().getName() + "_" + System.currentTimeMillis()); project.create(new NullProgressMonitor()); this.provisionedProjects.put(projectName, project); FileUtils.copyDirectory(folder, project.getLocation().toFile()); // workaround for https://github.com/OmniSharp/omnisharp-node-client/issues/265 ProcessBuilder dotnetRestoreBuilder = new ProcessBuilder(AcutePlugin.getDotnetCommand(), "restore"); dotnetRestoreBuilder.directory(project.getLocation().toFile()); assertEquals(0, dotnetRestoreBuilder.start().waitFor()); project.open(new NullProgressMonitor()); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); return project; } else { return null; } }
Example 8
Source File: TestImportXPDL.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Test public void testImportWithWhiteSpace() throws IOException { File destFile = new File("destImportWithWhiteSpace" + System.currentTimeMillis() + ".proc"); destFile.createNewFile(); destFile.deleteOnExit(); URL xpdlResource = FileLocator.toFileURL(getClass().getResource("Approval Workflow.xpdl")); XPDLToProc xpdlToProc = new XPDLToProc(); destFile = xpdlToProc.createDiagram(xpdlResource, new NullProgressMonitor()); ResourceSet resourceSet = new ResourceSetImpl(); Resource resource = resourceSet.getResource(toEMFURI(destFile), true); MainProcess mainProcess = (MainProcess) resource.getContents().get(0); assertNotNull("xpdl diagram \"Approval workflow\" was not exported correctly", mainProcess); resource.unload(); }
Example 9
Source File: TestAddJar.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public void testAddJar() throws IOException, OperationCanceledException { URL url = getClass().getResource("TestConnectorBis.jar"); url = FileLocator.toFileURL(url); File file = new File(url.getFile()); DependencyRepositoryStore drs = (DependencyRepositoryStore) RepositoryManager.getInstance() .getRepositoryStore(DependencyRepositoryStore.class); drs.importInputStream(file.getName(), new FileInputStream(file)); assertNotNull("Jar missing after import", drs.getChild(file.getName(), true)); }
Example 10
Source File: ZipUtil.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
public static File extractZip(URL zipProjectLocation, File destination) throws IOException { URL zipLocation = FileLocator.toFileURL(zipProjectLocation); if (!zipLocation.getProtocol().equals("file")) { throw new IOException("could not resolve location to a file"); } File zippedFile = new File(zipLocation.getPath()); assertTrue(zippedFile.exists()); IStatus status = unzip(zippedFile, destination, new NullProgressMonitor()); assertTrue("failed to extract: " + status, status.isOK()); return destination; }
Example 11
Source File: SpellCheckEngine.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Returns the locales for which this * spell check engine has dictionaries in certain location. * * @param location dictionaries location * @return The available locales for this engine */ private static Set<Locale> getLocalesWithInstalledDictionaries(URL location) { String[] fileNames; try { URL url= FileLocator.toFileURL(location); File file= new File(url.getFile()); if (!file.isDirectory()) return Collections.emptySet(); fileNames= file.list(); if (fileNames == null) return Collections.emptySet(); } catch (IOException ex) { LogHelper.logError(ex); return Collections.emptySet(); } Set<Locale> localesWithInstalledDictionaries= new HashSet<Locale>(); int fileNameCount= fileNames.length; for (int i= 0; i < fileNameCount; i++) { String fileName= fileNames[i]; int localeEnd= fileName.indexOf(".dictionary"); //$NON-NLS-1$ if (localeEnd > 1) { String localeName= fileName.substring(0, localeEnd); int languageEnd=localeName.indexOf('_'); if (languageEnd == -1) localesWithInstalledDictionaries.add(new Locale(localeName)); else if (languageEnd == 2 && localeName.length() == 5) localesWithInstalledDictionaries.add(new Locale(localeName.substring(0, 2), localeName.substring(3))); else if (localeName.length() > 6 && localeName.charAt(5) == '_') localesWithInstalledDictionaries.add(new Locale(localeName.substring(0, 2), localeName.substring(3, 5), localeName.substring(6))); } } return localesWithInstalledDictionaries; }
Example 12
Source File: ComponentsProvider.java From tesb-studio-se with Apache License 2.0 | 5 votes |
protected File getExternalComponentsLocation() { Bundle bundle = Activator.getBundle(); try { URL localURL = FileLocator.toFileURL( FileLocator.find(bundle, new Path("components"), null)); return new File(localURL.getPath()); } catch (Exception localException) { logger.error(localException); localException.printStackTrace(); } return null; }
Example 13
Source File: ViewerWebApp.java From birt with Eclipse Public License 1.0 | 5 votes |
private String getWebAppPath(Bundle bundle, String path) throws IOException { URL url = bundle.getEntry(path); if (url != null) { URL fileUrl = FileLocator.toFileURL(url); return fileUrl.getFile(); } return path; }
Example 14
Source File: SARLRuntimeTest.java From sarl with Apache License 2.0 | 5 votes |
private File getPackedSRE() throws Exception { URL url = Foo.class.getResource("/foo/foo2.jar"); assertNotNull(url); url = FileLocator.toFileURL(url); assertNotNull(url); File file = new File(url.getPath()); assertEquals("foo2.jar", file.getName()); return file; }
Example 15
Source File: TestMessageRefactoring.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private void importDiagrams() throws Exception { ImportBosArchiveOperation op = new ImportBosArchiveOperation(repositoryAccessor); URL bosArchiveURL = FileLocator .toFileURL(TestMessageRefactoring.class.getResource("TestRefactoringMessage.bos")); op.setArchiveFile(FileLocator.toFileURL(bosArchiveURL).getFile()); op.setCurrentRepository(repositoryAccessor.getCurrentRepository()); op.run(Repository.NULL_PROGRESS_MONITOR); }
Example 16
Source File: NodesLoader.java From jbt with Apache License 2.0 | 5 votes |
/** * Loads all the standard nodes defined in the file * {@link #STANDARD_NODES_FILE}. After doing so, standard nodes can be * accessed through {@link #getStandardNodes()} and * {@link #getNode(String, String)}. * <p> * Throws an exception if there is any error loading the standard nodes. */ public static void loadStandardNodes() throws IOException { loadRoot(); URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(STANDARD_NODES_FILE), Collections.EMPTY_MAP); URL fileUrl = null; fileUrl = FileLocator.toFileURL(url); FileInputStream file = new FileInputStream(fileUrl.getPath()); parseStandardNodesFile(file); }
Example 17
Source File: FindbugsTestPlugin.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
public File getFileInPlugin(IPath path) throws CoreException { try { URL installURL = new URL(getBundle().getEntry("/"), path.toString()); URL localURL = FileLocator.toFileURL(installURL); return new File(localURL.getFile()); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, e.getMessage(), e)); } }
Example 18
Source File: EclipsePlatform.java From birt with Eclipse Public License 1.0 | 4 votes |
public URL asLocalURL( URL url ) throws IOException { return FileLocator.toFileURL( url ); }
Example 19
Source File: TestNonInterruptingBoundaryTimerEvent.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Test public void testNonInterruptingBoundaryEvent() throws Exception { final ProcessAPI processApi = BOSEngineManager.getInstance().getProcessAPI(session); final ImportBosArchiveOperation op = new ImportBosArchiveOperation(repositoryAccessor); final URL fileURL1 = FileLocator .toFileURL(TestNonInterruptingBoundaryTimerEvent.class.getResource("TestNonInterruptingTimerEvent-1.0.bos")); //$NON-NLS-1$ op.setArchiveFile(FileLocator.toFileURL(fileURL1).getFile()); op.setCurrentRepository(repositoryAccessor.getCurrentRepository()); op.run(new NullProgressMonitor()); for (final IRepositoryFileStore f : op.getFileStoresToOpen()) { f.open(); } final ProcessDiagramEditor processEditor = (ProcessDiagramEditor) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage().getActiveEditor(); final MainProcess mainProcess = (MainProcess) processEditor.getDiagramEditPart().resolveSemanticElement(); assertEquals("TestNonInterruptingTimerEvent", mainProcess.getName()); final SearchOptions searchOptions = new SearchOptionsBuilder(0, 10).done(); final RunProcessCommand runProcessCommand = new RunProcessCommand(true); runProcessCommand.execute(ProcessSelector.createExecutionEvent((AbstractProcess) mainProcess.getElements().get(0))); final String urlGivenToBrowser = runProcessCommand.getUrl().toString(); assertFalse("The url contains null:" + urlGivenToBrowser, urlGivenToBrowser.contains("null")); final long processId = processApi.getProcessDefinitionId("TestNonInterruptingTimerEvent", "1.0"); final ProcessDefinition processDef = processApi.getProcessDefinition(processId); processApi.startProcess(processId); final boolean evaluateAsync = new TestAsyncThread(30, 1000) { @Override public boolean isTestGreen() throws Exception { final IdentityAPI identityApi = BOSEngineManager.getInstance().getIdentityAPI(session); final SearchResult<HumanTaskInstance> tasks = processApi.searchPendingTasksForUser( identityApi.getUserByUserName("walter.bates").getId(), searchOptions); int cpt = 0; for (final HumanTaskInstance instance : tasks.getResult()) { if (instance.getProcessDefinitionId() == processDef.getId()) { cpt++; } } return cpt == 2; } }.evaluate(); assertTrue("Invalid number of tasks", evaluateAsync); }
Example 20
Source File: ModelLibraryRunner.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public int start(final List<String> args) throws IOException { final Injector injector = HeadlessSimulationLoader.preloadGAMA(); final GamlModelBuilder builder = createBuilder(injector); final int[] count = { 0 }; final int[] code = { 0, 0 }; final Multimap<Bundle, String> plugins = GamaBundleLoader.getPluginsWithModels(); final List<URL> allURLs = new ArrayList<>(); for (final Bundle bundle : plugins.keySet()) { for (final String entry : plugins.get(bundle)) { final Enumeration<URL> urls = bundle.findEntries(entry, "*", true); if (urls != null) { while (urls.hasMoreElements()) { final URL url = urls.nextElement(); if (isModel(url)) { final URL resolvedFileURL = FileLocator.toFileURL(url); allURLs.add(resolvedFileURL); } } } } } builder.loadURLs(allURLs); // allURLs.forEach(u -> validate(builder, count, code, u)); final Map<String, Exception> errors = new HashMap<>(); allURLs.forEach(u -> validateAndRun(builder, errors, count, code, u, true, 1)); DEBUG.OUT("" + count[0] + " GAMA models compiled in built-in library and plugins. " + code[0] + " compilation errors found"); DEBUG.SECTION("SUMMARY"); errors.forEach((name, ex) -> DEBUG.OUT(name + " = " + ex.toString())); DEBUG.SECTION("SUMMARY"); // code[1] = code[0]; // code[0] = 0; // count[0] = 0; // final Multimap<Bundle, String> tests = GamaBundleLoader.getPluginsWithTests(); // allURLs = new ArrayList<>(); // for (final Bundle bundle : tests.keySet()) { // for (final String entry : tests.get(bundle)) { // final Enumeration<URL> urls = bundle.findEntries(entry, "*", true); // if (urls != null) // while (urls.hasMoreElements()) { // final URL url = urls.nextElement(); // if (isModel(url)) { // final URL resolvedFileURL = FileLocator.toFileURL(url); // allURLs.add(resolvedFileURL); // } // } // } // } // builder.loadURLs(allURLs); // // allURLs.forEach(u -> validate(builder, count, code, u)); // // DEBUG.OUT("" + count[0] + " GAMA tests compiled in built-in library and plugins. " + code[0] // + " compilation errors found"); // // DEBUG.OUT(code[0] + code[1]); return code[0] + code[1]; }