List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.entirej.ide.core.project.EJFormConsistencyChecker.java
License:Apache License
private void validateFile(IFile file, List<EJFormValidateProvider> providers, IProgressMonitor monitor) { if (providers.isEmpty()) return;/*from ww w . ja v a 2s .c om*/ try { // try to ignore outpu path IJavaProject project = JavaCore.create(file.getProject()); IPath outputLocation = project.getOutputLocation(); if (outputLocation.isPrefixOf(file.getFullPath())) return; } catch (JavaModelException e) { // ignore } IFile propFile = EJProject.getPropertiesFile(file.getProject()); if (propFile == null || !propFile.exists()) { return; } String message = NLS.bind("Validating {0} ...", file.getFullPath().toString()); monitor.subTask(message); SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, providers.size()); for (EJFormValidateProvider element : providers) { if (monitor.isCanceled()) return; element.validate(file, new SubProgressMonitor(subProgressMonitor, 1)); } subProgressMonitor.done(); monitor.subTask(" Updating ..."); monitor.done(); }
From source file:org.entirej.ide.core.project.EJPluginEntireJClassLoader.java
License:Apache License
public static Class<?> loadClass(final IJavaProject javaProject, String className) throws ClassNotFoundException { ClassLoader classLoader = WEAK_LOADERS.get(javaProject); if (classLoader == null) { classLoader = getClassloader(javaProject); WEAK_LOADERS.put(javaProject, classLoader); }/* w w w. ja va2s . c o m*/ try { Class<?> loadClass = classLoader.loadClass(className); if (loadClass != null) return loadClass; } catch (Throwable e) { // ignore } // get output path level call loading try { // javaProject.getResolvedClasspath(true);//make sure project in // build classLoader = new OutputClassLoader(javaProject.getOutputLocation(), classLoader); } catch (JavaModelException e) {// ignore } return classLoader.loadClass(className); }
From source file:org.entirej.ide.core.project.EJPluginEntireJClassLoader.java
License:Apache License
private static Collection<URL> getClasspathEntries(IJavaProject javaProject, boolean ignoreSource) { if (javaProject == null) { throw new NullPointerException( "Trying to get hte projects class path, but the project passed was null"); }//from ww w .ja v a 2 s . c om try { if (!javaProject.exists()) { return new ArrayList<URL>(); } // IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); List<URL> urlList = toURLS(javaProject, entries, ignoreSource); //add Project output path IPath outputLocation = null; try { outputLocation = javaProject.getOutputLocation(); IPath path = javaProject.getProject().getLocation(); outputLocation = path.append(outputLocation.removeFirstSegments(1)); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (outputLocation != null) { URL url = new URL("file", null, outputLocation.toString() + "/"); urlList.add(url); } return urlList; } catch (JavaModelException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } return null; }
From source file:org.entirej.ide.ui.editors.form.builder.EJFormConstBuilder.java
License:Apache License
private void genConstantFile(IFile file, IProgressMonitor monitor) { try {//from w w w . j a v a 2 s . c o m // try to ignore output path IJavaProject project = JavaCore.create(file.getProject()); IPath outputLocation = project.getOutputLocation(); if (outputLocation.isPrefixOf(file.getFullPath())) return; } catch (JavaModelException e) { // ignore } IFile propFile = EJProject.getPropertiesFile(file.getProject()); if (propFile == null || !propFile.exists()) { return; } String message = NLS.bind("Constants Generating {0} ...", file.getFullPath().toString()); monitor.subTask(message); SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 1); IProject _project = file.getProject(); IJavaProject project = JavaCore.create(_project); EJPluginFormProperties formProperties = getFormProperties(file, project); if (formProperties != null) buildFormConstant(project, formProperties, file, subProgressMonitor); subProgressMonitor.done(); monitor.subTask("Constants Updating ..."); monitor.done(); }
From source file:org.entirej.ide.ui.editors.form.builder.EJFormConstBuilder.java
License:Apache License
private void genPropertiesConstantFile(IFile file, IProgressMonitor monitor) { try {/*w w w . ja v a 2 s.c o m*/ // try to ignore output path IJavaProject project = JavaCore.create(file.getProject()); IPath outputLocation = project.getOutputLocation(); if (outputLocation.isPrefixOf(file.getFullPath())) return; } catch (JavaModelException e) { // ignore } IFile propFile = EJProject.getPropertiesFile(file.getProject()); if (propFile == null || !propFile.exists()) { return; } String message = NLS.bind("Constants Generating {0} ...", file.getFullPath().toString()); monitor.subTask(message); SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 1); IProject _project = file.getProject(); IJavaProject project = JavaCore.create(_project); EJPluginEntireJProperties entireJProperties = EJPluginEntireJPropertiesLoader.getEntireJProperties(project); if (entireJProperties != null) buildPropertiesConstant(project, entireJProperties, file, subProgressMonitor); subProgressMonitor.done(); monitor.subTask("Constants Updating ..."); monitor.done(); }
From source file:org.evosuite.eclipse.popup.actions.ExtendSuiteAction.java
License:Open Source License
/** * Add a new test generation job to the job queue * /*from w ww.j a v a 2s. c o m*/ * @param target */ @Override protected void addTestJob(final IResource target) { IJavaElement element = JavaCore.create(target); IJavaElement packageElement = element.getParent(); String packageName = packageElement.getElementName(); final String suiteClass = (!packageName.equals("") ? packageName + "." : "") + target.getName().replace(".java", "").replace(File.separator, "."); System.out.println("Building new job for " + suiteClass); DetermineSUT det = new DetermineSUT(); IJavaProject jProject = JavaCore.create(target.getProject()); try { String classPath = target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()) .getLocation().toOSString(); String SUT = det.getSUTName(suiteClass, classPath); // choose SelectionDialog typeDialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), target.getProject(), IJavaElementSearchConstants.CONSIDER_CLASSES, false); Object[] sutDefault = new Object[1]; sutDefault[0] = SUT; typeDialog.setInitialSelections(sutDefault); typeDialog.setTitle("Please select the class under test"); typeDialog.open(); // Type selected by the user Object[] result = typeDialog.getResult(); if (result.length > 0) { SourceType sourceType = (SourceType) result[0]; SUT = sourceType.getFullyQualifiedName(); } else { return; } Job job = new TestExtensionJob(shell, target, SUT, suiteClass); job.setPriority(Job.SHORT); IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); ISchedulingRule rule = ruleFactory.createRule(target.getProject()); //IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES); job.setRule(rule); job.setUser(true); job.schedule(); // start as soon as possible } catch (JavaModelException e) { e.printStackTrace(); } catch (NoJUnitClassException e) { MessageDialog.openError(shell, "Evosuite", "Cannot find JUnit tests in " + suiteClass); } }
From source file:org.evosuite.eclipse.popup.actions.TestGenerationJob.java
License:Open Source License
public TestGenerationJob(Shell shell, final IResource target, String targetClassName, String suiteClassName) { super("EvoSuite Test Generation: " + targetClassName); this.targetClass = targetClassName; if (suiteClassName == null || suiteClassName.isEmpty()) { String tmp = targetClassName.replace('.', File.separatorChar); suiteClassName = new String(tmp + Properties.JUNIT_SUFFIX + ".java"); }/*from ww w. j av a2 s . c o m*/ this.suiteClass = suiteClassName; this.target = target; this.shell = shell; IJavaProject jProject = JavaCore.create(target.getProject()); try { classPath = target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()).getLocation() .toOSString(); } catch (JavaModelException e) { e.printStackTrace(); classPath = ""; } }
From source file:org.evosuite.eclipse.popup.actions.TestGenerationJob.java
License:Open Source License
private String buildProjectCP() throws JavaModelException { IJavaProject jProject = JavaCore.create(target.getProject()); IClasspathEntry[] oldEntries = jProject.getRawClasspath(); String classPath = ""; boolean first = true; for (int i = 0; i < oldEntries.length; i++) { IClasspathEntry curr = oldEntries[i]; System.out.println("Current entry: " + curr.getPath()); if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = curr.getPath(); if (path.toFile().getName().startsWith("evosuite")) { System.out.println("Skipping evosuite.jar"); continue; }/* w ww .j a va2s. c o m*/ if (!first) classPath += File.pathSeparator; else first = false; if (path.toFile().exists()) { classPath += path.toOSString(); System.out.println("Adding CPE_LIBRARY to classpath: " + path.toOSString()); } else { classPath += target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString(); System.out.println("Adding CPE_LIBRARY to classpath: " + target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString()); } } else if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (curr.isExported()) { if (curr.toString().equals("org.eclipse.jdt.launching.JRE_CONTAINER")) { System.out.println("Found JRE container"); } else if (curr.toString().startsWith("org.eclipse.jdt.junit.JUNIT_CONTAINER")) { System.out.println("Found JUnit container"); } else { System.out.println("Found unknown container: " + curr); } } else { System.out.println("Container not exported: " + curr); } } else if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // Add binary dirs of this project to classpath System.out.println("Don't handle CPE_PROJECT yet"); } else if (curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { System.out.println("Path: " + curr.getPath()); System.out.println("Resolved Path: " + JavaCore.getResolvedVariablePath(curr.getPath())); if (!first) classPath += File.pathSeparator; else first = false; classPath += JavaCore.getResolvedVariablePath(curr.getPath()); } else if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { System.out.println("Don't handle CPE_SOURCE yet"); } else { System.out.println("CP type: " + curr.getEntryKind()); } } ResourceList.resetAllCaches(); if (!first) classPath += File.pathSeparator; classPath += target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()).getLocation() .toOSString(); return classPath; }
From source file:org.fastcode.util.SourceUtil.java
License:Open Source License
/** * * @param javaProject//w w w . ja va 2 s. co m * @return */ public static Set<String> getBinaryFoldersForJavaProject(final IJavaProject javaProject) { final Set<String> binaryFolders = new TreeSet<String>(); try { // Get default output folder location. IPath outputPath = javaProject.getOutputLocation(); if (outputPath != null) { binaryFolders.add(outputPath.toString()); } // Find all the output folders by looking for source folders. for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { outputPath = entry.getOutputLocation(); if (outputPath == null) { continue; } binaryFolders.add(outputPath.toString()); } } } catch (final JavaModelException e) { e.printStackTrace(); } return binaryFolders; }
From source file:org.gololang.gldt.jdt.internal.GoloBuilder.java
License:Apache License
private IPath isOnSourceRoot(IResource resource, IJavaProject javaProject) throws JavaModelException { IPath result = null;//from w ww.j av a 2 s .c o m IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) && entry.getPath().isPrefixOf(resource.getFullPath())) { result = entry.getOutputLocation(); if (result == null) { result = javaProject.getOutputLocation(); } break; } } return result; }