List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:ar.com.fluxit.jqa.JQAEclipseMarker.java
License:Open Source License
private void mark(IJavaProject targetProject, RuleCheckFailed ruleCheckFailed) { try {//from w ww.j a v a 2 s. c o m File violatedPath = BCERepositoryLocator.getRepository() .getSourceFile(ruleCheckFailed.getTargetClassName(), Utils.getSourcesDirs(targetProject)); for (Integer lineId : ruleCheckFailed.getLineIds()) { mark(violatedPath, lineId, ruleCheckFailed); } } catch (FileNotFoundException e) { throw new IllegalStateException("Can not found sources of project: " + targetProject.getElementName(), e); } catch (JavaModelException e) { throw new IllegalStateException("Can not parse Java project: " + targetProject.getElementName() + " while finding a source file", e); } }
From source file:ar.com.fluxit.jqa.JQAEclipseRunner.java
License:Open Source License
private void run(IResource rulesContextFile, IProject targetProject) throws RulesContextFactoryException, IntrospectionException, FileNotFoundException, TypeFormatException, IOException { final IJavaProject javaProject = JavaCore.create(targetProject); final RulesContextFactory rulesContextFactory = RulesContextFactoryLocator.getRulesContextFactory(); final RulesContext rulesContext = rulesContextFactory .getRulesContext(rulesContextFile.getRawLocation().toOSString()); try {//from w w w.ja v a 2 s .c om Collection<File> classPath = getClassPath(javaProject); Collection<File> classFiles = getClassFiles(javaProject); String sourceJavaVersion = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); File[] sourceDir = Utils.getSourcesDirs(javaProject); final CheckingResult checkResult = RulesContextChecker.INSTANCE.check(targetProject.getName(), classFiles, classPath, rulesContext, sourceDir, sourceJavaVersion, LOGGER); JQAEclipseMarker.INSTANCE.mark(javaProject, checkResult); } catch (JavaModelException e) { throw new IllegalStateException("Can not parse Java project: " + javaProject.getElementName(), e); } }
From source file:astrecognition.views.ProjectPickerDialog.java
License:Open Source License
public synchronized String getProjectName() throws Exception { IJavaProject javaProject = getProject(); if (javaProject != null) return javaProject.getElementName(); return ""; }
From source file:astrecognition.views.ProjectPickerDialog.java
License:Open Source License
private void addTable() throws Exception { // Add table to the dialog table = new Table(dialog, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); // GridData data = new GridData (SWT.FILL, SWT.FILL, true, true); GridData data = new GridData(); data.heightHint = 200;//w w w .ja v a 2s .c o m data.horizontalSpan = 2; data.horizontalAlignment = SWT.FILL; data.verticalAlignment = SWT.FILL; table.setLayoutData(data); table.setLinesVisible(true); table.setHeaderVisible(true); TableColumn column = new TableColumn(table, SWT.LEAD); column.setText("Java Project List"); JavaElementLabelProvider labelProvider = new JavaElementLabelProvider(); IJavaModel javaModel = Activator.getJavaModel(); IJavaProject[] javaProjects = javaModel.getJavaProjects(); TreeSet<IJavaProject> set = new TreeSet<IJavaProject>(new Comparator<IJavaProject>() { public int compare(IJavaProject thisP, IJavaProject thatP) { return thisP.getElementName().compareTo(thatP.getElementName()); } }); set.addAll(Arrays.asList(javaProjects)); for (IJavaProject javaProject : set) { TableItem item = new TableItem(table, SWT.NULL); item.setText(javaProject.getElementName()); System.out.println(javaProject.getElementName()); item.setImage(labelProvider.getImage(javaProject)); item.setData(javaProject); } column.pack(); column.setWidth(300); }
From source file:br.ufal.cideei.handlers.DoAnalysisOnClassPath.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { //#ifdef CACHEPURGE //@ br.Main.randomLong(); //#endif/* w w w . j av a2 s . c o m*/ // TODO: exteriorize this number as a configuration parameter. Abstract away the looping. try { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event); Object firstElement = selection.getFirstElement(); if (!(firstElement instanceof IJavaProject)) { throw new UnsupportedOperationException("Selected resource is not a java project"); } IJavaProject javaProject = (IJavaProject) firstElement; IClasspathEntry[] classPathEntries = null; try { classPathEntries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { e.printStackTrace(); throw new ExecutionException("No source classpath identified"); } /* * To build the path string variable that will represent Soot's classpath we will first iterate * through all libs (.jars) files, then through all source classpaths. * * FIXME: WARNING: A bug was found on Soot, in which the FileSourceTag would contain incorrect * information regarding the absolute location of the source file. In this workaround, the classpath * must be injected into the FeatureModelInstrumentorTransformer class (done through its * constructor). * * As a consequence, we CANNOT build an string with all classpaths that contains source code for the * project and thus one only source code classpath can be analysed at a given time. * * This seriously restricts the range of projects that can be analysed with this tool. */ List<IClasspathEntry> sourceClasspathEntries = new ArrayList<IClasspathEntry>(); StringBuilder libsPaths = new StringBuilder(); for (IClasspathEntry entry : classPathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = entry.getPath().makeAbsolute().toFile(); if (file.isAbsolute()) { libsPaths.append(file.getAbsolutePath() + File.pathSeparator); } else { libsPaths.append(ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath()) .getLocation().toOSString() + File.pathSeparator); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceClasspathEntries.add(entry); } } if (sourceClasspathEntries.size() != 1) { throw new UnsupportedOperationException("project must have exactly one source classpath entry"); } IClasspathEntry entry = sourceClasspathEntries.get(0); final int times = 10; for (int i = 0; i < times; i++) { // #ifdef METRICS String sinkFile = System.getProperty("user.home") + File.separator + javaProject.getElementName().trim().toLowerCase().replace(' ', '-') + "-fs"; // #ifdef LAZY sinkFile += "-lazy"; // #endif // #ifdef FEATUREMODEL //@ sinkFile += "-fm"; // #endif sink = new MetricsSink(new MetricsTable(new File(sinkFile + ".xls"))); // #endif this.addPacks(javaProject, entry, libsPaths.toString()); SootManager.reset(); // #ifdef METRICS sink.terminate(); // #endif System.out.println("=============" + (i + 1) + "/" + times + "============="); } sink.createSummaryFile(); } catch (Throwable e) { e.printStackTrace(); } finally { SootManager.reset(); // #ifdef METRICS if (sink != null && !sink.terminated()) { sink.terminate(); } // #endif } return null; }
From source file:br.ufal.cideei.handlers.DoAnalysisOnClassPath.java
License:Open Source License
/** * Configures the classpath, sets up the transformers, load (jimplify) classes and run the packs. * //from w w w . j a v a 2 s . c o m * @param javaProject * @param entry * @param libs */ private void addPacks(IJavaProject javaProject, IClasspathEntry entry, String libs) { /* * if the classpath entry is "", then JDT will complain about it. */ String classPath; if (entry.getPath().toOSString().equals(File.separator + javaProject.getElementName())) { classPath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); } else { classPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()).getLocation() .toOSString(); } SootManager.configure(classPath + File.pathSeparator + libs); System.out.println(classPath); IFeatureExtracter extracter = CIDEFeatureExtracterFactory.getInstance().getExtracter(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { IJavaElement[] children = null; try { children = packageFragmentRoot.getChildren(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (IJavaElement child : children) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] compilationUnits = null; try { compilationUnits = packageFragment.getCompilationUnits(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (ICompilationUnit compilationUnit : compilationUnits) { String fragmentName = packageFragment.getElementName(); String compilationName = compilationUnit.getElementName(); StringBuilder qualifiedNameStrBuilder = new StringBuilder(fragmentName); // If it's the default package: if (qualifiedNameStrBuilder.length() == 0) { // Remove ".java" suffix qualifiedNameStrBuilder.append(compilationName.substring(0, compilationName.length() - 5)); } else { // Remove ".java" suffix qualifiedNameStrBuilder.append(".") .append(compilationName.substring(0, compilationName.length() - 5)); } // This goes into Soot loadAndSupport SootManager.loadAndSupport(qualifiedNameStrBuilder.toString()); } } } Scene.v().loadNecessaryClasses(); AlloyConfigurationCheck alloyConfigurationCheck = null; // #ifdef FEATUREMODEL //@ try { //@ String absolutePath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); //@ alloyConfigurationCheck = new AlloyConfigurationCheck(absolutePath + File.separator + "fm.als"); //@ } catch (CannotReadAlloyFileException e) { //@ e.printStackTrace(); //@ return; //@ } // #endif addPacks(classPath, extracter, alloyConfigurationCheck); SootManager.runPacks(extracter); }
From source file:br.ufal.cideei.handlers.DoFeatureObliviousAnalysisOnClassPath.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try {/*from w w w . jav a 2 s . co m*/ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event); Object firstElement = selection.getFirstElement(); if (!(firstElement instanceof IJavaProject)) { throw new UnsupportedOperationException("selected resource is not a java project"); } IJavaProject javaProject = (IJavaProject) firstElement; IClasspathEntry[] classPathEntries = null; try { classPathEntries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { e.printStackTrace(); throw new ExecutionException("No source classpath identified"); } /* * To build the path string variable that will represent Soot's classpath we will first iterate * through all libs (.jars) files, then through all source classpaths. * * FIXME: WARNING: A bug was found on Soot, in which the FileSourceTag would contain incorrect * information regarding the absolute location of the source file. In this workaround, the classpath * must be injected into the FeatureModelInstrumentorTransformer class (done though its * constructor). * * As a consequence, we CANNOT build an string with all classpaths that contains source code for the * project and thus only one source code classpath can be analysed at a given time. * * This seriously restricts the range of projects that can be analysed with this tool. */ List<IClasspathEntry> sourceClasspathEntries = new ArrayList<IClasspathEntry>(); StringBuilder libsPaths = new StringBuilder(); for (IClasspathEntry entry : classPathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = entry.getPath().makeAbsolute().toFile(); if (file.isAbsolute()) { libsPaths.append(file.getAbsolutePath() + File.pathSeparator); } else { libsPaths.append(ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath()) .getLocation().toOSString() + File.pathSeparator); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceClasspathEntries.add(entry); } } if (sourceClasspathEntries.size() != 1) { throw new UnsupportedOperationException("project must have exactly one source classpath entry"); } IClasspathEntry entry = sourceClasspathEntries.get(0); final int times = 10; for (int i = 0; i < times; i++) { // #ifdef METRICS String sinkFile = System.getProperty("user.home") + File.separator + javaProject.getElementName().trim().toLowerCase().replace(' ', '-') + "-fo"; // #ifdef LAZY sinkFile += "-lazy"; // #endif // #ifdef FEATUREMODEL //@ sinkFile += "-fm"; // #endif sink = new MetricsSink(new MetricsTable(new File(sinkFile + ".xls"))); // #endif this.addPacks(javaProject, entry, libsPaths.toString()); SootManager.reset(); // #ifdef METRICS sink.terminate(); // #endif System.out.println("=============" + (i + 1) + "/" + times + "============="); } sink.createFeatureObliviousSummaryFile(); } catch (Throwable e) { e.printStackTrace(); } finally { SootManager.reset(); // #ifdef METRICS if (sink != null && !sink.terminated()) { sink.terminate(); } // #endif } return null; }
From source file:br.ufal.cideei.handlers.DoFeatureObliviousAnalysisOnClassPath.java
License:Open Source License
private void addPacks(IJavaProject javaProject, IClasspathEntry entry, String libs) { /*/*from ww w. j a v a 2 s . c o m*/ * if the classpath entry is "", then JDT will complain about it. */ String classPath; if (entry.getPath().toOSString().equals(File.separator + javaProject.getElementName())) { classPath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); } else { classPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()).getLocation() .toOSString(); } SootManager.configure(classPath + File.pathSeparator + libs); IFeatureExtracter extracter = CIDEFeatureExtracterFactory.getInstance().getExtracter(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { IJavaElement[] children = null; try { children = packageFragmentRoot.getChildren(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (IJavaElement child : children) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] compilationUnits = null; try { compilationUnits = packageFragment.getCompilationUnits(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (ICompilationUnit compilationUnit : compilationUnits) { String fragmentName = packageFragment.getElementName(); String compilationName = compilationUnit.getElementName(); StringBuilder qualifiedNameStrBuilder = new StringBuilder(fragmentName); // If it's the default package: if (qualifiedNameStrBuilder.length() == 0) { // Remove ".java" suffix qualifiedNameStrBuilder.append(compilationName.substring(0, compilationName.length() - 5)); } else { // Remove ".java" suffix qualifiedNameStrBuilder.append(".") .append(compilationName.substring(0, compilationName.length() - 5)); } // This goes into Soot loadAndSupport SootManager.loadAndSupport(qualifiedNameStrBuilder.toString()); } } } Scene.v().loadNecessaryClasses(); AlloyConfigurationCheck alloyConfigurationCheck = null; // #ifdef FEATUREMODEL //@ try { //@ String absolutePath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); //@ alloyConfigurationCheck = new AlloyConfigurationCheck(absolutePath + File.separator + "fm.als"); //@ } catch (CannotReadAlloyFileException e) { //@ e.printStackTrace(); //@ return; //@ } // #endif addPacks(classPath, extracter, alloyConfigurationCheck); SootManager.runPacks(extracter); }
From source file:br.ufscar.sas.ui.handlers.UI.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // get workbench window IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); // set selection service ISelectionService service = window.getSelectionService(); // set structured selection IStructuredSelection structured = (IStructuredSelection) service.getSelection(); //Progress Monitor ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell()); //Reset Perspective window.getActivePage().resetPerspective(); try {//from w w w . ja v a2 s.c o m dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { //Creates KDM instance int totalUnitsOfWork = IProgressMonitor.UNKNOWN; monitor.beginTask("Performing Reverse Engineering....", totalUnitsOfWork); // Call Reverse Engineering String javaProjectName = ""; String projectName = null; if (structured != null) { if (structured.getFirstElement() instanceof IJavaProject) { IJavaProject jProject = (IJavaProject) structured.getFirstElement(); projectName = jProject.getElementName(); } } javaProjectName = projectName; CreateKDM ck = new CreateKDM(); ck.createKDMFile(javaProjectName); monitor.done(); try { refreshProjects(); } catch (CoreException e) { e.printStackTrace(); } } }); //Show main View window.getActivePage().showView("MainView"); IWorkbenchPage ip = window.getActivePage(); IViewPart myView = ip.findView("org.eclipse.jdt.ui.SourceView"); ip.hideView(myView); myView = ip.findView("org.eclipse.jdt.ui.JavadocView"); ip.hideView(myView); myView = ip.findView("org.eclipse.ui.views.ProblemView"); ip.hideView(myView); myView = ip.findView("org.eclipse.mylyn.tasks.ui.views.tasks"); ip.hideView(myView); myView = ip.findView("org.eclipse.ui.views.ContentOutline"); ip.hideView(myView); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:ca.ecliptical.pde.internal.ds.DSAnnotationCompilationParticipant.java
License:Open Source License
@Override public int aboutToBuild(IJavaProject project) { if (debug.isDebugging()) debug.trace(String.format("About to build project: %s", project.getElementName())); //$NON-NLS-1$ int result = READY_FOR_BUILD; ProjectState state = null;/*from w ww . jav a2s.c om*/ try { Object value = project.getProject().getSessionProperty(PROP_STATE); if (value instanceof SoftReference<?>) { @SuppressWarnings("unchecked") SoftReference<ProjectState> ref = (SoftReference<ProjectState>) value; state = ref.get(); } } catch (CoreException e) { Activator.getDefault().getLog().log(e.getStatus()); } if (state == null) { try { state = loadState(project.getProject()); } catch (IOException e) { Activator.getDefault().getLog() .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error loading project state.", e)); //$NON-NLS-1$ } if (state == null) { state = new ProjectState(); result = NEEDS_FULL_BUILD; } try { project.getProject().setSessionProperty(PROP_STATE, new SoftReference<ProjectState>(state)); } catch (CoreException e) { Activator.getDefault().getLog().log(e.getStatus()); } } processingContext.put(project, new ProjectContext(state)); String path = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, Activator.PREF_PATH, Activator.DEFAULT_PATH, new IScopeContext[] { new ProjectScope(project.getProject()), InstanceScope.INSTANCE }); if (!path.equals(state.getPath())) { state.setPath(path); result = NEEDS_FULL_BUILD; } String errorLevelStr = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, Activator.PREF_VALIDATION_ERROR_LEVEL, ValidationErrorLevel.error.name(), new IScopeContext[] { new ProjectScope(project.getProject()), InstanceScope.INSTANCE }); ValidationErrorLevel errorLevel; try { errorLevel = ValidationErrorLevel.valueOf(errorLevelStr); } catch (IllegalArgumentException e) { errorLevel = ValidationErrorLevel.error; } if (errorLevel != state.getErrorLevel()) { state.setErrorLevel(errorLevel); result = NEEDS_FULL_BUILD; } return result; }