List of usage examples for org.eclipse.jdt.core IJavaProject getProject
IProject getProject();
IProject
on which this IJavaProject
was created. From source file:com.google.inject.tools.ideplugin.eclipse.EclipseJavaProject.java
License:Apache License
private String getProjectName(IJavaProject project) { return project.getProject().getName(); }
From source file:com.google.test.metric.eclipse.internal.core.TestabilityLauncher.java
License:Apache License
@SuppressWarnings("unchecked") public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { if (!TestabilityConstants.TESTABILITY.equals(mode)) { throw new IllegalStateException( "Cannot launch testability configuration when not in testability mode."); }//from w w w .j a va2s. c om String projectName = configuration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_PROJECT_NAME, ""); IJavaProject javaProject = javaProjectHelper.getJavaProject(projectName); String projectLocation = javaProjectHelper.getProjectLocation(javaProject); String[] classPaths = getClassPaths(javaProject, projectLocation); List<String> allJavaPackages = javaProjectHelper.getAllJavaPackages(javaProject); ClassPathFactory classPathFactory = new ClassPathFactory(); ClassPath classPath = classPathFactory.createFromPaths(classPaths); IPath pluginStateLocation = Activator.getDefault().getStateLocation(); String baseReportDirectoryString = configuration .getAttribute(TestabilityConstants.CONFIGURATION_ATTR_REPORT_FOLDER_NAME, ""); if ("".equals(baseReportDirectoryString)) { baseReportDirectoryString = pluginStateLocation.toOSString(); } File reportDirectory = new File(baseReportDirectoryString, javaProject.getProject().getName() + "-TestabilityReport"); if (!reportDirectory.exists()) { reportDirectory.mkdirs(); } int maxExcellentCost = configuration.getAttribute( TestabilityConstants.CONFIGURATION_ATTR_MAX_EXCELLENT_COST, TestabilityConstants.MAX_EXCELLENT_COST); int maxAcceptableCost = configuration.getAttribute( TestabilityConstants.CONFIGURATION_ATTR_MAX_ACCEPTABLE_COST, TestabilityConstants.MAX_ACCEPTABLE_COST); int maxClassesInReport = configuration.getAttribute( TestabilityConstants.CONFIGURATION_ATTR_MAX_CLASSES_IN_REPORT, TestabilityConstants.MAX_CLASSES_TO_SHOW_IN_ISSUES_REPORTER); double globalCost = configuration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_GLOBAL_STATE_COST, TestabilityConstants.GLOBAL_STATE_COST); double cyclomaticCost = configuration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_CYCLOMATIC_COST, TestabilityConstants.CYCLOMATIC_COST); double constructorMultiplier = configuration.getAttribute( TestabilityConstants.CONFIGURATION_ATTR_CONSTRUCTOR_MULT, TestabilityConstants.CONSTRUCTOR_MULT); int printDepth = TestabilityConstants.RECORDING_DEPTH; List<String> whitelistPackages = configuration .getAttribute(TestabilityConstants.CONFIGURATION_ATTR_WHITELIST, TestabilityConstants.WHITELIST); try { PrintStream reportStream = new PrintStream( new FileOutputStream(new File(reportDirectory, TestabilityConstants.HTML_REPORT_FILENAME))); PrintStream errorStream = new PrintStream( new FileOutputStream(new File(reportDirectory, TestabilityConstants.ERROR_LOG_FILENAME))); RegExpWhiteList whitelist = new RegExpWhiteList("java."); for (String packageName : whitelistPackages) { whitelist.addPackage(packageName); } CostModel costModel = new CostModel(cyclomaticCost, globalCost, constructorMultiplier); JavaClassRepository classRepository = new JavaClassRepository(classPath); MetricComputer computer = new MetricComputer(classRepository, errorStream, whitelist, printDepth); HypotheticalCostModel hypotheticalCostModel = new HypotheticalCostModel(costModel); IssuesReporter issuesReporter = new IssuesReporter(new TriageIssuesQueue<ClassIssues>(maxAcceptableCost, maxClassesInReport, new ClassIssues.TotalCostComparator()), hypotheticalCostModel); ReportOptions options = new ReportOptions(cyclomaticCost, globalCost, constructorMultiplier, maxExcellentCost, maxAcceptableCost, maxClassesInReport, -1, -1, printDepth, -1, "", ""); SourceLoader sourceLoader = new SourceLoader(classPath); AnalysisModel analysisModel = new AnalysisModel(issuesReporter); ReportModel reportModel = new HtmlReportModel(costModel, analysisModel, options); ReportGenerator report = new ReportGeneratorProvider(classPath, options, reportStream, hypotheticalCostModel, ReportFormat.html).build(costModel, reportModel, sourceLoader); new JavaTestabilityRunner(report, classPath, classRepository, computer, allJavaPackages, whitelist, errorStream).run(); boolean runningInCompilationMode = configuration .getAttribute(TestabilityConstants.CONFIGURATION_ATTR_RUNNING_IN_COMPILATION_MODE, false); notifyAllListeners(options, analysisModel.getWorstOffenders(), javaProject, reportDirectory, runningInCompilationMode); reportStream.flush(); reportStream.close(); } catch (Exception e) { logger.logException(e); } }
From source file:com.google.test.metric.eclipse.internal.util.JavaProjectHelper.java
License:Apache License
public String getProjectLocation(IJavaProject javaProject) { IProject project = javaProject.getProject(); IPath rawLocation = project.getRawLocation(); IPath projectLocation;//from ww w . j ava 2 s. c o m if (rawLocation != null) { projectLocation = rawLocation.removeLastSegments(1); } else { projectLocation = project.getParent().getLocation(); } return projectLocation.toOSString(); }
From source file:com.google.test.metric.eclipse.ui.internal.TestabilityReportLaunchListener.java
License:Apache License
private void createMarkersFromClassIssues(List<ClassIssues> classIssues, IJavaProject javaProject) throws CoreException { javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_COLLABORATOR_MARKER_TYPE, true, IResource.DEPTH_INFINITE);/*from w w w.j a v a 2 s . co m*/ javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_CONSTRUCTOR_MARKER_TYPE, true, IResource.DEPTH_INFINITE); javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_DIRECT_COST_MARKER_TYPE, true, IResource.DEPTH_INFINITE); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); List<IPath> sourceFolderPaths = new ArrayList<IPath>(); for (IPackageFragmentRoot root : roots) { if (!root.isArchive()) { IResource rootResource = root.getCorrespondingResource(); sourceFolderPaths.add(rootResource.getFullPath().removeFirstSegments(1)); } } for (ClassIssues classIssue : classIssues) { IResource resource = getAbsolutePathFromJavaFile(classIssue.getClassName(), sourceFolderPaths, javaProject.getProject()); if (resource != null) { for (Issue issue : classIssue.getMostImportantIssues()) { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); attributes.put(IMarker.LINE_NUMBER, issue.getLocation().getLineNumber()); attributes.put(IMarker.MESSAGE, retriever.getSuggestion(issue.getType(), issue.getSubType())); IssueType issueType = issue.getType(); attributes.put(TestabilityConstants.ISSUE_TYPE, issue.getType().toString()); String markerType = null; if (IssueType.COLLABORATOR.equals(issueType)) { markerType = TestabilityConstants.TESTABILITY_COLLABORATOR_MARKER_TYPE; } else if (IssueType.CONSTRUCTION.equals(issueType)) { markerType = TestabilityConstants.TESTABILITY_CONSTRUCTOR_MARKER_TYPE; } else if (IssueType.DIRECT_COST.equals(issueType)) { markerType = TestabilityConstants.TESTABILITY_DIRECT_COST_MARKER_TYPE; } if (markerType != null) { MarkerUtilities.createMarker(resource, attributes, markerType); } } } else { logger.logException("No Resource found for Class : " + classIssue.getClassName(), null); } } }
From source file:com.htmlhifive.tools.jslint.actions.AbstractJavaScriptAction.java
License:Apache License
@Override public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection select = (IStructuredSelection) selection; if (select.getFirstElement() instanceof IResource) { resource = (IResource) select.getFirstElement(); } else if (select.getFirstElement() instanceof IJavaProject) { IJavaProject project = (IJavaProject) select.getFirstElement(); resource = project.getProject(); }/*w w w . j a va2 s . c o m*/ } }
From source file:com.hudson.hibernatesynchronizer.dialog.SnippetChoiceDialog.java
License:GNU General Public License
public SnippetChoiceDialog(Shell parentShell, IJavaProject project) { super(parentShell); this.project = project; try {//from ww w.j a v a2 s . c o m this.allSnippets = TemplateManager.getInstance().getSnippets(project.getProject()); this.customSnippets = TemplateManager.getInstance().getCustomSnippetsOnly(project.getProject()); } catch (Exception ioe) { Plugin.logError(ioe); } }
From source file:com.hudson.hibernatesynchronizer.popup.actions.SynchronizeFiles.java
License:GNU General Public License
private void exec(IStructuredSelection selection, IProgressMonitor monitor) { Shell shell = new Shell(); Object[] obj = selection.toArray(); HibernateDOMParser domParser = null; Map fileMap = new HashMap(); IProject project = null;//from w w w. j a va 2s. com Map documents = new HashMap(); for (int i = 0; i < obj.length && !monitor.isCanceled(); i++) { if (obj[i] instanceof IFile) { IFile file = (IFile) obj[i]; HibernateEditor.initFile(file); project = file.getProject(); try { monitor.subTask(file.getName() + ": creating DOM"); domParser = new HibernateDOMParser(file.getContents()); Document doc = domParser.getDocument(); HibernateDocument hd = DOMHelper.getHibernateDocument(domParser, file.getProject()); documents.put(file, hd); List classes = hd.getClasses(); HibernateEditor.cache(file.getProject(), file.getFullPath().toFile(), classes); monitor.worked(1); } catch (SAXParseException e) { EditorUtil.addProblemMarker(file, e.getMessage(), e.getLineNumber()); } catch (NoRouteToHostException nrthe) { EditorUtil.addProblemMarker(file, "This is not synchronized with the Java model. A NoRouteToHostException occured while process the synchronization. Either remove the external namespace and DTD definitions or connect to the internet (or configure your proxy).", 1); MessageDialog.openError(shell, "An error has occured: NoRouteToHostException", "This usually occurs if you have namespace references or DTD validation and are either not connected to the internet or do not have your proxy setting correctly configured.\n\nPlease resolve these issues to use the HibernateSynchronizer plugin."); } catch (Throwable e) { EditorUtil.addProblemMarker(file, e.getMessage(), 1); MessageDialog.openError(shell, "An error has occured", e.getMessage()); Plugin.logError(e); } } } if (null == project) return; boolean valid = true; try { IJavaProject javaProject = JavaCore.create(project); IPackageFragmentRoot root = HSUtil.getProjectRoot(javaProject); if (valid && null != root) { Object contextObject = null; String customObjectStr = Plugin.getProperty(javaProject.getProject(), Constants.PROP_CONTEXT_OBJECT); if (null != customObjectStr && customObjectStr.trim().length() > 0) { ClassLoader loader = new ProjectClassLoader(javaProject, getClass().getClassLoader()); try { contextObject = loader.loadClass(customObjectStr).newInstance(); } catch (Exception e) { } } Context context = SynchronizerThread.getDefaultContext(null, javaProject, contextObject); try { Snippet snippet = TemplateManager.getInstance().findSnippetByName("Setup", javaProject.getProject()); if (null != snippet) { StringWriter sw = new StringWriter(); Constants.customGenerator.evaluate(context, sw, Velocity.class.getName(), snippet.getContent()); String trimmed = sw.toString().trim(); if (trimmed.startsWith(SynchronizerThread.WARNING)) { String message = trimmed.substring(SynchronizerThread.WARNING.length(), trimmed.length()); MessageDialog.openWarning(shell, "Warning", message); } else if (trimmed.startsWith(SynchronizerThread.ERROR)) { String message = trimmed.substring(SynchronizerThread.ERROR.length(), trimmed.length()); MessageDialog.openError(shell, "An error has occured", message); valid = false; } else if (trimmed.startsWith(SynchronizerThread.FATAL)) { String message = trimmed.substring(SynchronizerThread.FATAL.length(), trimmed.length()); MessageDialog.openError(shell, "An error has occured", message); valid = false; } } } catch (Exception e) { } if (valid) { for (int i = 0; i < obj.length && !monitor.isCanceled(); i++) { if (obj[i] instanceof IFile) { IFile file = (IFile) obj[i]; try { file.deleteMarkers(null, false, 1); monitor.subTask(file.getName() + ": retrieving hibernate class objects"); HibernateDocument hd = (HibernateDocument) documents.get(file); monitor.worked(1); if (null != hd) { List classes = hd.getClasses(); for (Iterator iter = classes.iterator(); iter.hasNext();) { HibernateClass hc = (HibernateClass) iter.next(); fileMap.put(hc, file); if (null == hc.getPackageName() || hc.getPackageName().length() == 0) { valid = false; } } SynchronizerThread.synchronize(javaProject, root, classes, monitor, file.getName(), file, context, force()); } } catch (HibernateSynchronizerException e) { int lineNumber = e.getLineNumber(); if (null != e.getNode() && null != domParser.getLineNumber(e.getNode())) { lineNumber = domParser.getLineNumber(e.getNode()).intValue(); } if (lineNumber <= 0) { lineNumber = 1; } EditorUtil.addProblemMarker(file, e.getMessage(), lineNumber); } catch (Throwable e) { EditorUtil.addProblemMarker(file, e.getMessage(), 1); MessageDialog.openError(shell, "An error has occured", e.getMessage()); Plugin.logError(e); } } } } } } catch (CoreException ce) { Plugin.logError(ce); } }
From source file:com.hudson.hibernatesynchronizer.popup.actions.TemplateGeneration.java
License:GNU General Public License
private Context getDefaultContext(StructuredSelection selection, IJavaProject project) { Context context = new VelocityContext(); List classes = getAllClasses(selection); if (null == classes) return null; context.put("classes", classes); context.put("project", project); context.put("hsUtil", new HSUtil()); if (classes.size() == 1) { context.put("class", classes.get(0)); }// w w w . java2 s. c o m context.put("now", new Date()); context.put("stringUtil", new StringUtils()); try { String customObjectStr = Plugin.getProperty(project.getProject(), Constants.PROP_CONTEXT_OBJECT); Object contextObject = null; if (null != customObjectStr && customObjectStr.trim().length() > 0) { ClassLoader loader = new ShallowProjectClassLoader(project, getClass().getClassLoader()); try { try { contextObject = loader.loadClass(customObjectStr).newInstance(); } catch (ClassNotFoundException e) { loader = new ProjectClassLoader(project, getClass().getClassLoader()); contextObject = loader.loadClass(customObjectStr).newInstance(); } } catch (Exception e) { } } if (null != contextObject) { if (contextObject instanceof Map) { for (Iterator i = ((Map) contextObject).entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); if (null != entry.getKey()) { context.put(entry.getKey().toString(), entry.getValue()); } } } context.put("obj", contextObject); } } catch (CoreException e) { } return context; }
From source file:com.hudson.hibernatesynchronizer.util.SynchronizerThread.java
License:GNU General Public License
public static Context getDefaultContext(HibernateClass hc, IJavaProject project) throws JavaModelException { Object contextObject = null;//from ww w. jav a2s. co m String customObjectStr = Plugin.getProperty(project.getProject(), Constants.PROP_CONTEXT_OBJECT); if (null != customObjectStr && customObjectStr.trim().length() > 0) { if (null != customObjectStr && customObjectStr.trim().length() > 0) { ClassLoader loader = new ProjectClassLoader(project, Synchronizer.class.getClassLoader()); try { contextObject = loader.loadClass(customObjectStr).newInstance(); } catch (Exception e) { } } } return getDefaultContext(hc, project, contextObject); }
From source file:com.hudson.hibernatesynchronizer.util.SynchronizerThread.java
License:GNU General Public License
public static Context getDefaultContext(HibernateClass hc, IJavaProject project, Object contextObject) { Context context = new VelocityContext(); context.put("now", new Date()); context.put("project", project); context.put("dollar", "$"); context.put("notDollar", "$!"); context.put("snippet", new SnippetContext(context, project.getProject())); String useCustomManager = Plugin.getProperty(project.getProject(), Constants.PROP_USE_CUSTOM_ROOT_DAO); if (null != useCustomManager && useCustomManager.equalsIgnoreCase(Boolean.TRUE.toString())) { String daoException = Plugin.getProperty(project.getProject(), Constants.PROP_BASE_DAO_EXCEPTION); if (null != daoException && daoException.trim().length() > 0) { context.put("exceptionClass", daoException.trim()); } else {/*from w w w .j a va2 s . c o m*/ context.put("exceptionClass", "net.sf.hibernate.HibernateException"); } } else { context.put("exceptionClass", "net.sf.hibernate.HibernateException"); } if (null != hc) context.put("class", hc); context.put("hsUtil", new HSUtil()); context.put("stringUtil", new StringUtils()); try { Map properties = TemplateManager.getInstance().getTemplateParameters(project.getProject()); for (Iterator i = properties.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); context.put((String) entry.getKey(), entry.getValue()); } } catch (CoreException ce) { } if (null != contextObject) { if (contextObject instanceof Map) { for (Iterator i = ((Map) contextObject).entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); if (null != entry.getKey()) { context.put(entry.getKey().toString(), entry.getValue()); } } } context.put("obj", contextObject); } return context; }