List of usage examples for org.eclipse.jdt.core IJavaProject getPath
IPath getPath();
From source file:de.lynorics.eclipse.jangaroo.m2e.JangarooProjectConfigurator.java
License:Open Source License
private void addSourcePath(IJavaProject javaProject, List<IClasspathEntry> entries, String path) throws JavaModelException { IPath srcPath = javaProject.getPath().append(path); IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath, null); boolean found = false; for (IClasspathEntry entry : entries) { if (entry.getPath().makeRelative().toString().equals(srcEntry.getPath().makeRelative().toString())) { found = true;//www.ja v a2s . co m break; } } if (!found) { entries.add(JavaCore.newSourceEntry(srcEntry.getPath())); } }
From source file:de.lynorics.eclipse.jangaroo.m2e.JangarooProjectConversionParticipant.java
License:Open Source License
private void configureBuildSourceDirectories(Model model, IJavaProject javaProject) throws CoreException { IClasspathEntry[] entries = javaProject.getRawClasspath(); Set<String> sources = new LinkedHashSet<String>(); Set<String> potentialTestSources = new LinkedHashSet<String>(); Set<String> potentialResourceDirectories = new LinkedHashSet<String>(); Set<String> potentialTestResourceDirectories = new LinkedHashSet<String>(); IPath projectPath = javaProject.getPath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entries[i].getPath().makeRelativeTo(projectPath); if (path.isAbsolute()) { //We only support paths relative to the project root, so we skip this one continue; }//from www. ja v a 2 s .c o m String portablePath = path.toPortableString(); boolean isPotentialTestSource = isPotentialTestSource(path); boolean isResource = false; if (isPotentialTestSource) { // if(DEFAULT_TEST_RESOURCES.equals(portablePath)) { // isResource = potentialTestResourceDirectories.add(portablePath); // } else { // potentialTestSources.add(portablePath); // } } else { if (DEFAULT_RESOURCES.equals(portablePath)) { isResource = potentialResourceDirectories.add(portablePath); } else { sources.add(portablePath); } } if (!isResource) { //For source folders not already flagged as resource folder, check if // they contain non-java sources, so we can add them as resources too boolean hasNonJangarooResources = false; IFolder folder = javaProject.getProject().getFolder(path); if (folder.isAccessible()) { NonJangarooResourceVisitor nonJangarooResourceVisitor = new NonJangarooResourceVisitor(); try { folder.accept(nonJangarooResourceVisitor); } catch (NonJangarooResourceFoundException ex) { //Expected hasNonJangarooResources = true; } catch (CoreException ex) { //385666 ResourceException is thrown in Helios if (ex.getCause() instanceof NonJangarooResourceFoundException) { hasNonJangarooResources = true; } else { // log.error("An error occured while analysing {} : {}", folder, ex.getMessage()); } } } if (hasNonJangarooResources) { if (isPotentialTestSource) { potentialTestResourceDirectories.add(portablePath); } else { potentialResourceDirectories.add(portablePath); } } } } } Build build = getOrCreateBuild(model); if (!sources.isEmpty()) { if (sources.size() > 1) { //We don't know how to handle multiple sources, i.e. how to map to a resource or test source directory //That should be dealt by setting the build-helper-plugin config (http://mojo.codehaus.org/build-helper-maven-plugin/usage.html) // log.warn("{} has multiple source entries, this is not supported yet", model.getArtifactId()); //$NON-NLS-1$ } String sourceDirectory = sources.iterator().next(); if (!DEFAULT_JANGAROO_SOURCE.equals(sourceDirectory)) { build.setSourceDirectory(sourceDirectory); } for (String resourceDirectory : potentialResourceDirectories) { if (!DEFAULT_RESOURCES.equals(resourceDirectory) || potentialResourceDirectories.size() > 1) { build.addResource(createResource(resourceDirectory)); } } } if (!potentialTestSources.isEmpty()) { if (potentialTestSources.size() > 1) { // log.warn("{} has multiple test source entries, this is not supported yet", model.getArtifactId()); //$NON-NLS-1$ } // String testSourceDirectory = potentialTestSources.iterator().next(); // if(!DEFAULT_JAVA_TEST_SOURCE.equals(testSourceDirectory)) { // build.setTestSourceDirectory(testSourceDirectory); // } // for(String resourceDirectory : potentialTestResourceDirectories) { // if(!DEFAULT_TEST_RESOURCES.equals(resourceDirectory) || potentialTestResourceDirectories.size() > 1) { // build.addTestResource(createResource(resourceDirectory)); // } // } } //Ensure we don't attach a new empty build definition to the model if (build.getSourceDirectory() != null || build.getTestSourceDirectory() != null || !build.getResources().isEmpty() || !build.getTestResources().isEmpty()) { model.setBuild(build); } }
From source file:es.bsc.servicess.ide.ProjectMetadata.java
License:Apache License
/** Get the Java Package root of the Service source folder * @param project Java project where the service is implemented * @return/*from ww w . j av a 2s . co m*/ * @throws JavaModelException */ public IPackageFragmentRoot getPackageFragmentRoot(IJavaProject project) throws JavaModelException { return project.findPackageFragmentRoot(project.getPath().append(getSourceDir())); }
From source file:fede.workspace.dependencies.eclipse.java.ItemDependenciesClasspathResolver.java
License:Apache License
public Object getComparisonID(IPath containerPath, IJavaProject project) { if (containerPath == null || project == null) { return null; }/*from w w w . java2 s . c o m*/ return containerPath.segment(0) + "/" + project.getPath().segment(0); //$NON-NLS-1$ }
From source file:gov.redhawk.ide.codegen.java.AbstractJavaCodeGenerator.java
License:Open Source License
/** * @since 5.0/* w w w . ja va 2 s. com*/ */ @Override public IStatus generate(final ImplementationSettings implSettings, final Implementation impl, final PrintStream out, final PrintStream err, // SUPPRESS CHECKSTYLE Arguments final IProgressMonitor monitor, final String[] generateFiles, final boolean shouldGenerate, final List<FileToCRCMap> crcMap) { final int STANDARD_WORK = 1; final int GENERATE_CODE_WORK = 30; final int CLEANUP_PROJECT_WORK = 2; final SubMonitor progress = SubMonitor.convert(monitor, "Configuring project", STANDARD_WORK + STANDARD_WORK + STANDARD_WORK + STANDARD_WORK + GENERATE_CODE_WORK + CLEANUP_PROJECT_WORK); final MultiStatus retStatus = new MultiStatus(JavaGeneratorPlugin.PLUGIN_ID, IStatus.OK, "Java code generation problems", null); final IResource resource = ModelUtil.getResource(implSettings); final IProject project = resource.getProject(); final IPath destinationBinDirectory = new Path(implSettings.getOutputDir()).append("bin"); final IPath destinationSrcDirectory = new Path(implSettings.getOutputDir()).append("src"); final SoftPkg softPkg = (SoftPkg) impl.eContainer(); final String prefix = CodegenFileHelper.getPreferredFilePrefix(softPkg, implSettings); softPkg.getDescriptor().getComponent().getComponentFeatures().getPorts(); final IPath outputPath = new Path(implSettings.getOutputDir()); final IResource outputDir = project.findMember(outputPath); final boolean outputExists = (outputDir != null); final IFolder srcDir = project.getFolder(destinationSrcDirectory); final boolean srcExists = srcDir.exists(); IJavaProject javaProject = null; if (!outputExists) { try { ResourceUtils.create(outputDir, progress.newChild(STANDARD_WORK)); } catch (final CoreException e) { retStatus.add(new Status(IStatus.ERROR, JavaGeneratorPlugin.PLUGIN_ID, "Unable to create implementation directory", e)); return retStatus; } } progress.setWorkRemaining(STANDARD_WORK + STANDARD_WORK + GENERATE_CODE_WORK + CLEANUP_PROJECT_WORK); try { javaProject = JavaGeneratorUtils.addJavaProjectNature(project, progress.newChild(STANDARD_WORK)); } catch (final CoreException e) { retStatus.add(new Status(IStatus.WARNING, JavaGeneratorPlugin.PLUGIN_ID, "Unable to add Java project nature", e)); } if (javaProject != null) { try { final IPath srcPath = new Path(javaProject.getPath().toString() + "/" + destinationSrcDirectory); final IPath binPath = new Path(javaProject.getPath().toString() + "/" + destinationBinDirectory); JavaGeneratorUtils.addSourceClassPaths(javaProject, srcPath, binPath, progress.newChild(STANDARD_WORK)); } catch (final CoreException e) { retStatus.add(new Status(IStatus.WARNING, JavaGeneratorPlugin.PLUGIN_ID, "Unable to add Java source path", e)); } try { JavaGeneratorUtils.addRedhawkJavaClassPaths(javaProject, progress.newChild(STANDARD_WORK)); } catch (final CoreException e) { retStatus.add(new Status(IStatus.WARNING, JavaGeneratorPlugin.PLUGIN_ID, "Unable to add setup Java class paths", e)); } } if (!srcExists) { try { ResourceUtils.create(srcDir, progress.newChild(STANDARD_WORK)); } catch (final CoreException ex) { retStatus.add(new Status(IStatus.ERROR, JavaGeneratorPlugin.PLUGIN_ID, "Unable to create 'src' directory", ex)); return retStatus; } } if (shouldGenerate) { out.println("Targeting location " + project.getLocation() + "/" + implSettings.getOutputDir() + " for code generation..."); try { generateCode(impl, implSettings, project, prefix, out, err, progress.newChild(GENERATE_CODE_WORK), generateFiles, crcMap); } catch (final CoreException ex) { retStatus.add( new Status(IStatus.ERROR, JavaGeneratorPlugin.PLUGIN_ID, "Unable to generate code", ex)); return retStatus; } final IStatus status = cleanupSourceFolders(project, progress.newChild(CLEANUP_PROJECT_WORK)); if (!status.isOK()) { retStatus.add(status); if (status.getSeverity() == IStatus.ERROR) { return retStatus; } } } return retStatus; }
From source file:gov.redhawk.ide.codegen.java.internal.OssieLibClasspathContainerInitializer.java
License:Open Source License
@Override public Object getComparisonID(final IPath containerPath, final IJavaProject project) { if (containerPath == null || project == null) { return null; }//w ww . ja va2s . c o m return containerPath.segment(0) + "/" + project.getPath().segment(0); //$NON-NLS-1$ }
From source file:it.scoppelletti.sdk.ide.projects.DependenciesContainerInitializer.java
License:Apache License
/** * Restituisce l’oggetto che identifica il class-path ai fini di * confronto./*from w w w . j ava 2 s .c o m*/ * * @param containerPath Identificatore del class-path. * @param project Progetto. * @return Oggetto. */ @Override public Object getComparisonID(IPath containerPath, IJavaProject project) { String path; if (containerPath == null || project == null) { return null; } path = containerPath.segment(0); path.concat("/"); path.concat(project.getPath().segment(0)); return path; }
From source file:it.wallgren.android.platform.project.AndroidPlatformProject.java
License:Apache License
private void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException { if (project == null) { throw new IllegalStateException("Project must be created before giving it a Java nature"); }/*from www . j av a2s . c om*/ final IFolder repoLink = createRepoLink(monitor, project, repoPath); IFile classpath = repoLink.getFile("development/ide/eclipse/.classpath"); IFile classpathDestination = project.getFile(".classpath"); if (classpathDestination.exists()) { classpathDestination.delete(true, monitor); } classpath.copy(classpathDestination.getFullPath(), true, monitor); final IProjectDescription description = project.getDescription(); final String[] natures = description.getNatureIds(); final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); @SuppressWarnings("rawtypes") final Map options = javaProject.getOptions(true); // Compliance level need to be 1.6 JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options); javaProject.setOptions(options); IClasspathEntry[] classPath = mangleClasspath(javaProject.getRawClasspath(), project, repoLink); javaProject.setRawClasspath(classPath, monitor); javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor); }
From source file:it.wallgren.android.platform.project.PackagesProject.java
License:Apache License
private void addJavaNature(IClasspathEntry[] classPath, IProject project, IProgressMonitor monitor) throws CoreException { if (project == null) { throw new IllegalStateException("Project must be created before giving it a Java nature"); }//from ww w .j a va2 s. co m final IProjectDescription description = project.getDescription(); final String[] natures = description.getNatureIds(); final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); @SuppressWarnings("rawtypes") final Map options = javaProject.getOptions(true); // Compliance level need to be 1.6 JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options); javaProject.setOptions(options); javaProject.setRawClasspath(classPath, monitor); javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor); }
From source file:me.gladwell.eclipse.m2e.android.configuration.MavenAndroidClasspathConfigurer.java
License:Open Source License
public void addGenFolder(IJavaProject javaProject, AndroidProject project, IClasspathDescriptor classpath) { // Remove so that we always add the gen after our src folder. This means that the source directory will // be used as the source attachment rather than the gen folder. IPath gen = javaProject.getPath().append(ANDROID_GEN_PATH); if (classpath.containsPath(gen)) { classpath.removeEntry(gen);/*from w w w. j av a 2 s . c o m*/ } IPath classesOutput = javaProject.getPath().append(ANDROID_CLASSES_FOLDER); classpath.addSourceEntry(gen, classesOutput, true); }