/** * Populate properties with everything required for the SonarLint analysis in issues mode. * * @param monitor * @param properties * @return */ public Properties configureAnalysis( final IProgressMonitor monitor, List<SonarLintProperty> extraProps) { Properties properties = new Properties(); IProject project = request.getProject(); final File baseDir = project.getLocation().toFile(); IPath projectSpecificWorkDir = project.getWorkingLocation(SonarLintCorePlugin.PLUGIN_ID); // Preview mode by default properties.setProperty( SonarLintProperties.ANALYSIS_MODE, SonarLintProperties.ANALYSIS_MODE_ISSUES); // Configuration by configurators (common and language specific) configure(project, this.request.getOnlyOnFiles(), properties, monitor); // Append workspace and project properties for (SonarLintProperty sonarProperty : extraProps) { properties.put(sonarProperty.getName(), sonarProperty.getValue()); } if (this.request.getOnlyOnFiles() != null) { Collection<String> paths = new ArrayList<>(this.request.getOnlyOnFiles().size()); for (IFile file : this.request.getOnlyOnFiles()) { MarkerUtils.deleteIssuesMarkers(file); paths.add(file.getProjectRelativePath().toString()); } ProjectConfigurator.setPropertyList(properties, "sonar.tests", paths); ProjectConfigurator.setPropertyList(properties, "sonar.sources", paths); } else { MarkerUtils.deleteIssuesMarkers(project); } properties.setProperty(SonarLintProperties.PROJECT_BASEDIR, baseDir.toString()); properties.setProperty(SonarLintProperties.WORK_DIR, projectSpecificWorkDir.toString()); return properties; }
/** * Convert a file to the EPackage containing a metamodel. * * @param iFile The file that is to be converted to the Epackage. * @return The EPackage containing the metamodel loaded from the file. * @throws CodeGenerationException */ protected EPackage fileToEPack(IFile iFile) throws CodeGenerationException { ResourceSet resSet = new ResourceSetImpl(); resSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap()); URI fileURI = URI.createPlatformResourceURI( "/" + iFile.getProject().getName() + "/" + iFile.getProjectRelativePath().toString(), true); Resource resource = resSet.createResource(fileURI); Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, "UTF-8"); try { resource.load(options); } catch (IOException e) { throw new CodeGenerationException( "Error while loading resource of File: " + iFile.getName(), e.getCause()); } EList<EObject> sd = resource.getContents(); for (EObject object : sd) { if (object instanceof EPackage) { EPackage ePack = (EPackage) object; pi.setNsURI(ePack.getNsURI()); return ePack; } } return null; }
private void replaceToReference(MapEntryModel entry) { for (DFPropModel child : entry.getChild()) { if (child instanceof MapModel) { boolean update = false; DFPropModel[] elements = child.getChild(); for (int i = 0; i < elements.length; i++) { DFPropModel element = elements[i]; if (element instanceof NamedModel) { try { IFile refFile = getReferencesFile((NamedModel) element); if (refFile.exists()) { String source = getReferencesSource(refFile); DFPropFileModel propModel = new DFPropModelParser().parse(source); propModel.setFileName(refFile.getName()); propModel.setFilePath(refFile.getProjectRelativePath().toString()); propModel.setReferences(true); elements[i] = new DFPropReferenceModel((NamedModel) element, propModel); update = true; } } catch (CoreException e) { } } } if (update) { ((MapModel) child).replaceChild(elements); } } } }
@Override public void performApply(ILaunchConfigurationWorkingCopy config) { config.setAttribute( IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, StringUtils.trimToEmpty(txtProject.getText())); try { List<String> stories = getStoriesFullPaths(); config.setAttribute(ILaunchConstants.LAUNCH_ATTR_STORIES_FULL_PATH, stories); } catch (CoreException cex) { EasybLaunchActivator.Log( "Unable apply configuration due to exception while retrieving story locations", cex); setErrorMessage( "Unable apply configuration due to exception while retrieving story locations"); } if (container != null) { config.setAttribute( ILaunchConstants.LAUNCH_ATTR_CONTAINER_HANDLE, container.getHandleIdentifier()); } if (storyFile != null) { config.setAttribute( ILaunchConstants.LAUNCH_ATTR_STORY_PATH, storyFile.getProjectRelativePath().toPortableString()); } config.setAttribute( ILaunchConstants.LAUNCH_ATTR_IS_SINGLE_STORY, btnRadioSingleStory.getSelection()); }
protected void projectChanged() { projectText = projectCombo.getText(); IJavaProject selectedProject = null; for (int i = 0; i < gwtProjects.length; i++) { IJavaProject gwtProject = gwtProjects[i]; if (projectText.equals(gwtProject.getProject().getName())) { selectedProject = gwtProject; break; } } if (selectedProject != null) { try { moduleCombo.removeAll(); List modulesList = Util.findModules(selectedProject); for (Iterator i = modulesList.iterator(); i.hasNext(); ) { IFile file = (IFile) i.next(); IPath projectRelativePath = file.getProjectRelativePath(); String fileName = file.getName(); String moduleName = fileName.substring(0, fileName.length() - Constants.GWT_XML_EXT.length() - 1); moduleCombo.add(projectRelativePath.toString()); moduleCombo.setData(moduleName, file); } int i = modulesList.indexOf(selectedModule); if (i == -1) i = 0; moduleCombo.select(i); moduleText = moduleCombo.getText(); } catch (CoreException e) { Activator.logException(e); } } doStatusUpdate(); }
protected IStatus run(IProgressMonitor monitor) { ArrayList<IFile> files = new ArrayList<IFile>(10); for (IResource resource : resources) { getFilesFromResouce(resource, files); } int count = files.size(); monitor.beginTask("Validating ...", count); int completed = 0; for (IFile file : files.toArray(new IFile[0])) { monitor.setTaskName( "Validating " + file.getProjectRelativePath().toString() + " (" + (completed + 1) + "/" + count + ")"); validateFile(file, monitor); monitor.worked(++completed); if (monitor.isCanceled()) return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
/** * this will convert the IO file name of the resource bundle to java package name * * @param project * @param value - the io file name * @return - the java package name of the resource bundle */ public static String convertIOToJavaFileName(IProject project, String value) { String rbIOFile = value.substring(value.lastIndexOf("/") + 1); // $NON-NLS-1$ IFile resourceBundleFile = null; IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot wroot = workspace.getRoot(); IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project); for (IClasspathEntry iClasspathEntry : cpEntries) { if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) { IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation(); entryPath = entryPath.append(rbIOFile); resourceBundleFile = wroot.getFileForLocation(entryPath); // System.out.println( "ResourceBundleValidationService.validate():" + resourceBundleFile ); if (resourceBundleFile != null && resourceBundleFile.exists()) { break; } } } String javaName = resourceBundleFile.getProjectRelativePath().toPortableString(); if (javaName.indexOf('.') != -1) { // Strip the extension javaName = value.substring(0, value.lastIndexOf('.')); // Replace all "/" by "." javaName = javaName.replace('/', '.'); } return javaName; }
public static boolean isController(IFile currentFile) { if (currentFile == null) return false; IPath controllerFilePath = currentFile.getProjectRelativePath(); if (controllerFilePath.segmentCount() < 2) return false; return controllerFilePath.segment(controllerFilePath.segmentCount() - 2).equals(CONTROLLERS) && controllerFilePath.lastSegment().endsWith(CONTROLLER_FILE_SUFFIX); }
public static String getModelNamePlural(IFile modelFile) { IPath modelFilePath = modelFile.getProjectRelativePath(); String modelFilename = modelFilePath.lastSegment(); if (!CakePHPHelper.isModel(modelFile)) return null; String singular = modelFilename.substring(0, modelFilename.indexOf('.')); String plural = Inflector.pluralize(singular); return plural; }
public static boolean isModel(IFile currentFile) { if (currentFile == null) return false; IPath modelFilePath = currentFile.getProjectRelativePath(); if (modelFilePath.segmentCount() < 2) return false; boolean isModel = modelFilePath.segment(modelFilePath.segmentCount() - 2).equalsIgnoreCase(MODELS) && modelFilePath.lastSegment().endsWith(PHP); return isModel; }
/** Suite file launcher. The <code>IFile</code> must exist in the workbench. */ public static void launchSuiteConfiguration( IFile suiteFile, String mode, ILaunchConfiguration prevConfig, Set failureDescriptions) { final IProject project = suiteFile.getProject(); final String fileConfName = suiteFile.getProjectRelativePath().toString().replace('/', '.'); final String suitePath = suiteFile.getLocation().toOSString(); launchSuiteConfiguration( project, fileConfName, suitePath, mode, prevConfig, failureDescriptions); }
public static IFile getModelFromController(IFile controllerFile) { if (!isController(controllerFile)) return null; IPath controllerFilePath = controllerFile.getProjectRelativePath(); String controllerFilename = controllerFilePath.lastSegment(); IPath model = getModelFromController(controllerFilePath, getModelName(controllerFilename)); IFile file = controllerFile.getProject().getFile(model); return file; }
public void testMoveProjectWithVirtualFolder() { IPath fileLocation = getRandomLocation(); IPath folderLocation = getRandomLocation(); IFile file = existingVirtualFolderInExistingProject.getFile(getUniqueString()); IFolder folder = existingVirtualFolderInExistingProject.getFolder(getUniqueString()); IFile childFile = folder.getFile(getUniqueString()); IResource[] oldResources = new IResource[] {existingProject, file, folder, childFile}; try { assertDoesNotExistInWorkspace("1.0", new IResource[] {folder, file, childFile}); try { createFileInFileSystem(fileLocation); folderLocation.toFile().mkdir(); folder.createLink(folderLocation, IResource.NONE, getMonitor()); file.createLink(fileLocation, IResource.NONE, getMonitor()); childFile.create(getRandomContents(), true, getMonitor()); } catch (CoreException e) { fail("2.0", e); } // move the project IProject destinationProject = getWorkspace().getRoot().getProject("MoveTargetProject"); assertDoesNotExistInWorkspace("3.0", destinationProject); try { existingProject.move(destinationProject.getFullPath(), IResource.SHALLOW, getMonitor()); } catch (CoreException e) { fail("4.0", e); } IFile newFile = destinationProject.getFile(file.getProjectRelativePath()); IFolder newFolder = destinationProject.getFolder(folder.getProjectRelativePath()); IFile newChildFile = newFolder.getFile(childFile.getName()); IResource[] newResources = new IResource[] {destinationProject, newFile, newFolder, newChildFile}; assertExistsInWorkspace("5.0", newResources); assertDoesNotExistInWorkspace("6.1", oldResources); assertTrue("7.0", existingProject.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("8.0", destinationProject.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("9.0", newFile.getParent().isVirtual()); assertTrue("10.0", newFile.isLinked()); assertTrue("11.0", newFolder.isLinked()); assertTrue("12.0", newFolder.getParent().isVirtual()); } finally { Workspace.clear(fileLocation.toFile()); Workspace.clear(folderLocation.toFile()); } }
protected IFile getReferencesFile(NamedModel element) { IFile file = ((IFileEditorInput) getEditorInput()).getFile(); IProject project = file.getProject(); IPath projectRelativePath = file.getProjectRelativePath(); String fileExtension = projectRelativePath.getFileExtension(); IPath prefix = projectRelativePath.removeLastSegments(1); String nameSegment = projectRelativePath.removeFileExtension().lastSegment(); IPath referencesPath = prefix.append(nameSegment + "_" + element.getNameText()).addFileExtension(fileExtension); IFile refFile = project.getFile(referencesPath.toString()); return refFile; }
public static IFile getControllerFromView(IFile viewFile) { if (!isView(viewFile)) return null; IPath viewFilePath = viewFile.getProjectRelativePath(); String plural = getPluralResourceNameFromViewPath(viewFilePath); String controllerName = plural + CONTROLLER_FILE_SUFFIX; IPath controllerPath = getAppFolderFromView(viewFilePath).append(CONTROLLERS).append(controllerName); IFile file = viewFile.getProject().getFile(controllerPath); return file; }
static Pair<String, String> getFileAndProject(IEditorInput input) { String path; String projectName; if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); path = file.getProjectRelativePath().toString(); projectName = file.getProject().getName(); } else { path = input.getName(); projectName = null; } return Pair.newInstance(path, projectName); }
private IFile getNotationInfoFile(IFile semanticInfoFile) { IProject project = semanticInfoFile.getProject(); IPath semanticInfoPath = semanticInfoFile.getProjectRelativePath(); IPath notationInfoPath = semanticInfoPath .removeLastSegments(1) .append(getNotationInfoFileName(semanticInfoFile.getName())); IFile notationInfoFile = project.getFile(notationInfoPath); if (!notationInfoFile.exists()) { createNotationInfoFile(notationInfoFile); } return notationInfoFile; }
public static IFile getViewFromAction(IFile controllerFile, String action) { if (!isController(controllerFile)) return null; IPath controllerFilePath = controllerFile.getProjectRelativePath(); String[] keys = splitAction(action); String view = keys[0]; if (view == null || view.length() == 0) { view = getControllerBaseName(controllerFilePath.lastSegment()); // view = view.substring(0, 1).toUpperCase() + view.substring(1); view = Inflector.humanize(view); } action = keys[1]; IPath viewPath = getAppFolderFromController(controllerFilePath).append(VIEWS).append(view); return getPreferenceViewFile(controllerFile.getProject(), viewPath, action); }
@Override public void launch(IEditorPart editor, final String mode) { Activator.logInfo("launch shortcut: editor" + editor.getTitle() + " mode " + mode); IEditorInput ei = editor.getEditorInput(); if (ei != null && ei instanceof FileEditorInput) { FileEditorInput fei = (FileEditorInput) ei; IFile file = fei.getFile(); final String fName = file.getProjectRelativePath().toOSString(); final String pName = file.getProject().getName(); launch(pName, fName, mode); } }
public static boolean isView(IFile currentFile) { if (currentFile == null) return false; IPath viewFilePath = currentFile.getProjectRelativePath(); if (viewFilePath.segmentCount() < 3) return false; String view = viewFilePath.segment(viewFilePath.segmentCount() - 3); if (!view.equals(VIEWS)) { return false; } String[] viewExts = getAvailableViewExts(); String name = viewFilePath.lastSegment(); for (int I = 0; I < viewExts.length; ++I) { if (name.endsWith(viewExts[I])) { return true; } } return false; }
public static boolean isJSFile(IFile selectedFile) { if (selectedFile == null) return false; IPath viewFilePath = selectedFile.getProjectRelativePath(); if (viewFilePath.segmentCount() < 3) return false; String view = viewFilePath.segment(viewFilePath.segmentCount() - 3); if (!view.equals(JS)) { return false; } String[] jsExts = getAvailableJSExts(); String name = viewFilePath.lastSegment(); for (int I = 0; I < jsExts.length; ++I) { if (name.endsWith(jsExts[I])) { return true; } } return false; }
public static IFile getControllerFromModel(IFile modelFile) { IPath modelFilePath = modelFile.getProjectRelativePath(); // String modelFilename = modelFilePath.lastSegment(); // if (!CakePHPHelper.isModel(modelFile)) // return null; // String singular = modelFilename.substring(0, modelFilename.indexOf('.')); // String plural = Inflector.pluralize(singular); String plural = getModelNamePlural(modelFile); String controllerName = plural + CONTROLLER_FILE_SUFFIX; IPath controllerPath = getAppFolderFromModel(modelFilePath).append(CONTROLLERS).append(controllerName); IFile file = modelFile.getProject().getFile(controllerPath); return file; }
public static IFile getJSFileFromView(IFile selectedFile) { if (!isView(selectedFile)) { return null; } IPath viewPath = selectedFile.getProjectRelativePath(); int segmentCount = viewPath.segmentCount(); if (segmentCount < 3) { return null; } String modelName = viewPath.segment(segmentCount - 2); String[] split = viewPath.lastSegment().split("\\."); String viewName = split[0]; IPath jsPath = getJSFileFromApp(getAppFolderFromView(viewPath), modelName, viewName); IFile file = selectedFile.getProject().getFile(jsPath); return file; }
/** * Create DFMapModel for Document. * * @return Map Property Model Object. */ protected DFPropFileModel createDFModel() { IEditorInput input = getEditorInput(); IDocument document = getDocumentProvider().getDocument(input); String source = document.get(); DFPropFileModel propModel = new DFPropModelParser().parse(source); String name = input.getName(); propModel.setFileName(name); if (input instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) input).getFile(); propModel.setFilePath(file.getProjectRelativePath().toString()); } if (canSplitMapFile()) { loadReferenceModel(propModel); } return propModel; }
/** * Copies the project information related to folders from the source node to the target node. As * in this special case there is no need for a source node, it purely creational operation. * * @see ProjectFileHandler#copyProjectInfo(Node, Node, IProject, TreeMap, TreeMap, boolean) * @param document the document to contain the result, used to create the XML nodes. * @param file the file to use. * @return the resulting target node. */ public static Node copyDefaultFileProperties(final Document document, final IFile file) { final Element root = document.createElement(FILERESOURCEXMLNODE); final Element filePath = document.createElement(FILEPATHXMLNODE); filePath.appendChild(document.createTextNode(file.getProjectRelativePath().toPortableString())); root.appendChild(filePath); final Element fileProperties = document.createElement(FILEPROPERTIESXMLNODE); final Element excludeFromBuild = document.createElement(EXCLUDEFROMBUILDXMLNODE); excludeFromBuild.appendChild(document.createTextNode(FALSE_STRING)); fileProperties.appendChild(excludeFromBuild); root.appendChild(fileProperties); return root; }
protected void handleScanButtonPressed() { ScannedFilesContentProvider contentProvider = new ScannedFilesContentProvider(suffixesText.getText()); CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog( SpringUIUtils.getStandardDisplay().getActiveShell(), new ScannedFilesLabelProvider(), contentProvider) { @Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Label note = new Label(composite, SWT.WRAP); note.setText(BeansUIPlugin.getResourceString(SCAN_NOTE_LABEL)); note.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return composite; } }; dialog.setTitle(BeansUIPlugin.getResourceString(DIALOG_TITLE)); dialog.setMessage(BeansUIPlugin.getResourceString(DIALOG_MESSAGE)); dialog.addFilter(new ConfigFileFilter(project.getConfigSuffixes())); dialog.setValidator(new StorageSelectionValidator(true)); dialog.setInput(project.getProject()); dialog.setSorter(new JavaElementSorter()); dialog.setInitialSelections(contentProvider.getElements(project.getProject())); if (dialog.open() == Window.OK) { Object[] selection = dialog.getResult(); if (selection != null && selection.length > 0) { for (Object element : selection) { String config; if (element instanceof ZipEntryStorage) { ZipEntryStorage storage = (ZipEntryStorage) element; config = storage.getFullName(); } else { IFile file = (IFile) element; config = file.getProjectRelativePath().toString(); } project.addConfig(config, IBeansConfig.Type.MANUAL); } configsViewer.refresh(false); hasUserMadeChanges = true; } } }
public static IFile getViewFromJSFile(IFile selectedFile) { if (!isJSFile(selectedFile)) return null; IPath selectedFilePath = selectedFile.getProjectRelativePath(); // String[] keys = splitAction(selectedFilePath.lastSegment()); String[] keys = selectedFilePath.lastSegment().split("\\."); String view = keys[0]; int segmentCount = selectedFilePath.segmentCount(); if (segmentCount < 3) { return null; } String modelName = selectedFilePath.segment(segmentCount - 2); // TODO: there's got to be a better way to do this IPath viewPath = getAppFolderFromJSFile(selectedFilePath) .append(VIEWS) .append(Inflector.pluralize(modelName)); return getPreferenceViewFile(selectedFile.getProject(), viewPath, view); }
public String getXtextPath() { if (createdProject != null) { FileFinderVisitor odesignProjectVisitor = new FileFinderVisitor("xtext"); try { createdProject.accept(odesignProjectVisitor); IFile odesignIFile = odesignProjectVisitor.getFile(); if (odesignIFile != null) { return "/" + createdProject.getName() + "/" + odesignIFile.getProjectRelativePath().toString(); } } catch (CoreException e) { Activator.error(e.getMessage(), e); } } return ""; }
@Override public void launch(ISelection selection, final String mode) { Activator.logInfo("launch shortcut: selection " + selection + " mode " + mode); if (selection != null) { if (selection instanceof TreeSelection) { TreeSelection ts = (TreeSelection) selection; Object e = ts.getFirstElement(); if (e instanceof IFile) { IFile file = (IFile) e; final String fName = file.getProjectRelativePath().toOSString(); final String pName = file.getProject().getName(); launch(pName, fName, mode); } } } }
@Override protected Control createContents(final Composite parent) { mic = new ModuleInclusionComposite(parent, SWT.NONE); IFile f = (IFile) getElement(); IContainer src = ResourceUtil.getSourceContainer(f); if (src != null) { info = new ModuleCreationInfo(); info.setSourceContainer(src); IPath p = ResourceUtil.getSourceRelativePath(src, f); info.setFolders(p); info.setModuleName(f.getProjectRelativePath().removeFileExtension().lastSegment()); mic.init(f, src, info.getQualifiedModuleName(), false); } else { mic.initNoSourceFolder(); } Dialog.applyDialogFont(parent); return mic; }