List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:net.harawata.mybatipse.mybatis.MybatipseXmlUtil.java
License:Open Source License
public static String getJavaMapperFqn(IJavaProject project, IResource resource) { IPath path = null;// www . j a v a 2s . c om if (resource != null) { path = resource.getFullPath(); } else { IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow window = wb.getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); IEditorPart editor = page.getActiveEditor(); IEditorInput input = editor.getEditorInput(); path = ((FileEditorInput) input).getFile().getFullPath(); } try { for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getPath().isPrefixOf(path)) { IPath relativePath = path.makeRelativeTo(entry.getPath()); return relativePath.removeFileExtension().toString().replace('/', '.'); } } } catch (JavaModelException e) { Activator.log(Status.ERROR, "Failed to get raw classpath for project: " + project.getElementName(), e); } return null; }
From source file:net.harawata.mybatipse.mybatis.TypeAliasCache.java
License:Open Source License
public TypeAliasMap getTypeAliasMap(IJavaProject javaProject, IReporter reporter) { String projectName = javaProject.getElementName(); TypeAliasMap aliasMap = projectCache.get(projectName); if (aliasMap == null) { Map<IFile, IContentType> configFiles = ConfigRegistry.getInstance().get(javaProject); aliasMap = new TypeAliasMap(); projectCache.put(projectName, aliasMap); packageCache.remove(projectName); superTypeCache.remove(projectName); Set<String> packages = new TreeSet<String>(); packageCache.put(projectName, packages); Set<String> superTypes = new HashSet<String>(); superTypeCache.put(projectName, superTypes); // Lookup the settings. IPreferenceStore store = Activator.getPreferenceStore(javaProject.getProject()); String storedValue = store.getString(PREF_CUSTOM_TYPE_ALIASES); StringTokenizer tokenizer = new StringTokenizer(storedValue, "\t"); while (tokenizer.hasMoreElements()) { String token = (String) tokenizer.nextElement(); if (token == null) continue; token = token.trim();/*from w ww.j a v a 2s.c o m*/ if (token.length() == 0) continue; try { int colonIdx = token.indexOf(':'); if (colonIdx == -1) { IType type = javaProject.findType(token); if (type == null) packages.add(token); else { String alias = getAliasAnnotationValue(type); aliasMap.put(alias, token); } } else if (colonIdx > 0 && colonIdx < token.length() - 2) { String qualifiedName = token.substring(0, colonIdx); IType type = javaProject.findType(qualifiedName); if (type == null) { Activator.log(Status.WARNING, "Missing '" + qualifiedName + "' specified in the custom type alias setting."); } else { // Look for @Alias first. String alias = getAliasAnnotationValue(type); if (alias == null) alias = token.substring(colonIdx + 1); aliasMap.put(alias, qualifiedName); } } } catch (JavaModelException e) { Activator.log(Status.ERROR, e.getMessage(), e); } } // Parse config xml files (mybatis and spring). for (Entry<IFile, IContentType> configFile : configFiles.entrySet()) { parseConfigFiles(javaProject, configFile.getKey(), configFile.getValue(), aliasMap, packages, superTypes, reporter); } // Search calls registering type aliases in java code. // scanJavaConfig(javaProject, aliasMap, packages, reporter); // Scan classes in the packages. if (!packages.isEmpty()) { collectTypesInPackages(javaProject, packages, aliasMap, superTypes, reporter); } } return aliasMap; }
From source file:net.harawata.mybatipse.wizard.NewXmlMapperWizard.java
License:Open Source License
private String guessNamespace(IFile file) { IProject project = file.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { IPath fullPath = file.getFullPath(); try {/*from w ww .ja v a 2s . c om*/ for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getPath().isPrefixOf(fullPath)) { IPath relativePath = fullPath.makeRelativeTo(entry.getPath()); return relativePath.removeFileExtension().toString().replace('/', '.'); } } } catch (JavaModelException e) { Activator.log(Status.ERROR, "Failed to get raw classpath for project: " + javaProject.getElementName(), e); } } // empty string to raise warning return ""; }
From source file:net.sf.fjep.fatjar.popup.actions.BuildFatJar.java
License:Open Source License
private String doCollectFatJar(IJavaProject jproject, IProgressMonitor iprogressmonitor, Set excludes, ArrayList includes, boolean onejar, String onejarexpand) throws IOException { Shell shell = new Shell(); String jartype = onejar ? "One-JAR" : "Fat Jar"; iprogressmonitor.subTask("Collect " + jartype + " - reading classpath"); Vector childProjects = new Vector(); Vector jarFiles = new Vector(); Vector classesDirs = new Vector(); Vector libDirs = new Vector(); Vector libNames = new Vector(); getChildProjects(jproject, childProjects, false); for (int i = childProjects.size() - 1; i >= 0; i--) { IJavaProject jChildProject = (IJavaProject) childProjects.get(i); if (onejar) { // Ferenc: libNames have to be updated for every new entry in // libdirs. // dirname is not unique, so using enumeration of childproject // name String childProjectName = jChildProject.getElementName(); int current = libDirs.size(); getClassPathJars(jChildProject, jarFiles, libDirs, true); for (int j = 1; j <= libDirs.size() - current; j++) { String libDir = (String) libDirs.get(j - 1); int start = libDir.indexOf(childProjectName); if (start >= 0) { start += childProjectName.length() + 1; String libName = libDir.substring(start).replace(File.separatorChar, PATH_SEPARATOR); libNames.add(libName); } else { libNames.add(childProjectName + PATH_SEPARATOR + Integer.toString(i)); }//from w w w . j a va 2s .c o m } getClassesDir(jChildProject, libDirs); libNames.add(childProjectName); } else { getClassPathJars(jChildProject, jarFiles, classesDirs, true); getClassesDir(jChildProject, classesDirs); } } if (onejar) { int current = libDirs.size(); String projectName = jproject.getElementName(); getClassPathJars(jproject, jarFiles, libDirs, false); for (int i = 1; i <= libDirs.size() - current; i++) { String libDir = (String) libDirs.get(i - 1); int start = libDir.indexOf(projectName); if (start >= 0) { start += projectName.length() + 1; String libName = libDir.substring(start).replace(File.separatorChar, PATH_SEPARATOR); libNames.add(libName); } else { libNames.add(projectName + PATH_SEPARATOR + Integer.toString(i)); } } } else { getClassPathJars(jproject, jarFiles, classesDirs, false); } getClassesDir(jproject, classesDirs); String projectDir = getProjectDir(jproject); String projectName = getProjectName(jproject); String tempdir = configGetTempBuildDir(jproject); boolean mergeManifests = configGetManifestMergeAll(jproject); mkdir(tempdir); ManifestData manifestData = null; if (mergeManifests) manifestData = new ManifestData(); iprogressmonitor.worked(PROGRESS_COLLECT * 1 / 20); for (int i = 0; i < jarFiles.size(); i++) { String jarFile = (String) jarFiles.get(i); String jarname = File.separatorChar + jarFile; jarname = jarname.substring(jarname.lastIndexOf(File.separatorChar) + 1); iprogressmonitor.subTask("Collect " + jartype + " - extracting " + jarname); if (!checkFileInList(jarFile, excludes) && !checkFileInList(jarname, excludes)) extractJar(jarFile, tempdir, manifestData, onejar); iprogressmonitor.worked(PROGRESS_COLLECT * 15 / 20 / jarFiles.size()); } for (int i = 0; i < classesDirs.size(); i++) { String classesDir = (String) classesDirs.get(i); iprogressmonitor.subTask("Collect " + jartype + " - copying class files " + classesDir); if (!onejar) { copyFiles(classesDir, tempdir, excludes, jproject); } else { // there is only one element in classesDirs if onejar is true, // so this code is only executed once. String mainClass = configGetMainClass(jproject); if (mainClass == null || mainClass.length() == 0) throw new IOException("Main-Class manifest entry cannot be missing in a One-JAR application"); String classPath = configGetClassPath(jproject); copyJar(classesDir, tempdir, excludes, mainClass, classPath, "main/main.jar", jproject); copyOneJARBootFiles(tempdir); } iprogressmonitor.worked(PROGRESS_COLLECT * 2 / 20 / classesDirs.size()); } // One-JAR supporting libraries taken from other projects classes. for (int i = 0; i < libDirs.size(); i++) { String classesDir = (String) libDirs.get(i); copyJar(classesDir, tempdir, excludes, null, null, "lib/" + libNames.get(i) + ".jar", jproject); } for (int i = 0; i < includes.size(); i++) { String include = (String) includes.get(i); String[] basedir_relpath = include.split("[|]"); String baseDir = basedir_relpath[0]; String relPath = ""; if (basedir_relpath.length > 1) relPath = File.separatorChar + basedir_relpath[1]; iprogressmonitor.subTask("Collect " + jartype + " - including resource files " + relPath); String src = baseDir + relPath; String dest = tempdir + relPath; File fsrc = new File(src); File fdest = new File(dest); fdest.getParentFile().mkdirs(); recursiveCopyFiles(fsrc, fdest); } iprogressmonitor.worked(PROGRESS_COLLECT * 1 / 20); iprogressmonitor.subTask("Collect " + jartype + " creating manifest"); mkdir(tempdir + File.separator + "META-INF"); if (manifestData == null) manifestData = new ManifestData(); String manifestFile = configGetManifestFile(jproject); if (manifestFile.equals("<createnew>")) { manifestData.clearMainSection(); manifestData.addMainSectionLine("Manifest-Version: 1.0"); if (onejar) { manifestData.addMainSectionLine("Created-By: Fat Jar/One-JAR Eclipse Plug-In"); manifestData.addMainSectionLine("Main-Class: com.simontuffs.onejar.Boot"); if (onejarexpand.length() > 0) manifestData.addMainSectionLine("One-Jar-Expand: " + onejarexpand); } else { manifestData.addMainSectionLine("Created-By: Fat Jar Eclipse Plug-In"); String mainClass = configGetMainClass(jproject); if ((mainClass != null) && !mainClass.equals("")) manifestData.addMainSectionLine("Main-Class: " + mainClass); String classPath = configGetClassPath(jproject); if ((classPath != null) && !classPath.equals("")) manifestData.addMainSectionLine("Class-Path: " + classPath); } } else { manifestData.addFile(projectDir + File.separator + manifestFile); } String manifestText = manifestData.toString(); writeTextToFile(new File(tempdir + File.separator + "META-INF" + File.separator + "MANIFEST.MF"), manifestText); iprogressmonitor.worked(PROGRESS_COLLECT * 1 / 20); return tempdir; }
From source file:net.sf.fjep.fatjar.popup.actions.BuildFatJar.java
License:Open Source License
public FJTree buildTree(IJavaProject jproject) { String projectName = jproject.getElementName(); FJTree rootNode = new FJTree(null, FJTree.NT_ROOT, "Fat Jar Tree for Project " + projectName, jproject, FJTree.CS_CHECKED);//from w ww. j a v a 2 s . c om Vector childProjects = new Vector(); Vector jarFiles = new Vector(); Vector classesDirs = new Vector(); getClassPathJars(jproject, jarFiles, classesDirs, false); getClassesDir(jproject, classesDirs); String classesDir = (String) classesDirs.lastElement(); rootNode.addChild(FJTree.NT_PROJECT_OUTPUT, "Project '" + jproject.getElementName() + "' output", new File(classesDir), FJTree.CS_CHECKED); for (int i = 0; i < classesDirs.size() - 1; i++) { classesDir = (String) classesDirs.get(i); rootNode.addChild(FJTree.NT_CLASSES, "Classes '" + classesDir + "'", new File(classesDir), FJTree.CS_CHECKED); } getChildProjects(jproject, childProjects, false); for (int i = 0; i < childProjects.size(); i++) { IJavaProject jChildProject = (IJavaProject) childProjects.get(i); String childProjectName = jChildProject.getElementName(); classesDirs.clear(); getClassPathJars(jChildProject, jarFiles, classesDirs, true); getClassesDir(jChildProject, classesDirs); classesDir = (String) classesDirs.lastElement(); rootNode.addChild(FJTree.NT_PROJECT_OUTPUT, "Project '" + childProjectName + "' output", new File(classesDir), FJTree.CS_CHECKED); for (int j = 0; j < classesDirs.size() - 1; j++) { classesDir = (String) classesDirs.get(j); rootNode.addChild(FJTree.NT_CLASSES, "Classes '" + classesDir + "'", new File(classesDir), FJTree.CS_CHECKED); } } for (int i = 0; i < jarFiles.size(); i++) { int checkd = FJTree.CS_CHECKED; String jarFile = (String) jarFiles.get(i); if (jarFile.endsWith(AguiConstants.AGUI_SDK_JAR)) { checkd = FJTree.CS_UNCHECKED; } String jarname = File.separatorChar + jarFile; jarname = jarname.substring(jarname.lastIndexOf(File.separatorChar) + 1); rootNode.addChild(FJTree.NT_JAR, jarname, new File(jarFile), checkd); } // include AguiManifest.xml String aguiManifestPath = BaseProjectHelper.getManifest(jproject.getProject()).getRawLocation().toFile() .getAbsolutePath(); rootNode.addChild(FJTree.NT_FILE, AguiConstants.AGUI_MANIFEST, new File(aguiManifestPath), FJTree.CS_CHECKED); // res String aguiResPath = BaseProjectHelper.getResFolder(jproject.getProject()).getRawLocation().toFile() .getAbsolutePath(); rootNode.addChild(FJTree.NT_DIR, AguiConstants.FD_RES, new File(aguiResPath), FJTree.CS_CHECKED); return rootNode; }
From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java
License:Open Source License
public JProjectConfiguration(IJavaProject jproject, ILaunchConfiguration launchConfig) { this.jproject = jproject; if (launchConfig == null) { String prjName = jproject.getElementName(); launchConfig = findConfiguration(FATJAR_CONFIG_PREFIX + prjName); if (launchConfig == null) { launchConfig = createConfiguration(FATJAR_CONFIG_PREFIX + prjName, prjName); }/* w w w . java 2 s . c o m*/ } this.launchConfig = launchConfig; }
From source file:net.sourceforge.eclipsejetty.launch.configuration.JettyLaunchConfigurationTab.java
License:Apache License
/** * Selects a Java project/* w w w . java 2 s .c o m*/ */ protected void chooseJavaProject() { ILabelProvider labelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT); ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider); dialog.setTitle(Messages.configTab_projectBrowseTitle); dialog.setMessage(Messages.configTab_projectBrowseMessage); try { dialog.setElements(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects()); } catch (JavaModelException e) { JettyPlugin.error(Messages.configTab_projectBrowseFailed, e); } IJavaProject javaProject = null; String projectName = projectText.getText().trim(); if (projectName.length() > 0) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); javaProject = JavaCore.create(workspaceRoot).getJavaProject(projectName); } if (javaProject != null) { dialog.setInitialSelections(new Object[] { javaProject }); } if (dialog.open() == Window.OK) { IJavaProject selectedProject = (IJavaProject) dialog.getFirstResult(); projectName = selectedProject.getElementName(); projectText.setText(projectName); } }
From source file:net.sourceforge.eclipsejetty.launch.JettyLaunchConfigurationTab.java
License:Apache License
protected void chooseJavaProject() { final ILabelProvider labelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT); final ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider); dialog.setTitle("Project Selection"); dialog.setMessage("Select a project to constrain your search."); try {//w w w .java 2s .c o m dialog.setElements(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects()); } catch (final JavaModelException jme) { JettyPlugin.logError(jme); } IJavaProject javaProject = null; String projectName = projectText.getText().trim(); if (projectName.length() > 0) { final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); javaProject = JavaCore.create(workspaceRoot).getJavaProject(projectName); } if (javaProject != null) { dialog.setInitialSelections(new Object[] { javaProject }); } if (dialog.open() == Window.OK) { final IJavaProject selectedProject = (IJavaProject) dialog.getFirstResult(); projectName = selectedProject.getElementName(); projectText.setText(projectName); } }
From source file:net.sourceforge.metrics.builder.MetricsBuilder.java
License:Open Source License
/** * Do a full build and recalculate metrics for all java resources in the project * /*from w w w . j a v a 2 s.c om*/ * @param monitor * @throws CoreException */ protected void fullBuild(IJavaProject currentProject, IProgressMonitor monitor) throws CoreException { MetricsBuildVisitor v = new MetricsBuildVisitor(monitor); Cache.singleton.clear(currentProject.getElementName()); getProject().accept(v); checkCancel(monitor); v.execute(); }
From source file:nz.ac.massey.cs.barrio.srcgraphbuilder.ExtractDependencyGraphJob.java
License:Apache License
public ExtractDependencyGraphJob(IJavaProject project) { super("Loading graph dependency extractor..."); setUser(true); // this is a user-spawned job this.project = project; this.context = new ExplorationContext(); this.context.setName(project.getElementName()); this.context.setDescription("Eclipse Java project " + project.getElementName()); }