List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:org.cloudfoundry.ide.eclipse.internal.server.core.CloudUtil.java
License:Open Source License
private static boolean isLiftLibrary(IClasspathEntry entry) { if (entry.getPath() != null) { String name = entry.getPath().lastSegment(); return Pattern.matches("lift-webkit.*\\.jar", name); }//from w ww. j ava 2s . com return false; }
From source file:org.cloudfoundry.ide.eclipse.internal.server.core.CloudUtil.java
License:Open Source License
private static boolean isSpringLibrary(IClasspathEntry entry) { if (entry.getPath() != null) { String name = entry.getPath().lastSegment(); return Pattern.matches(".*spring.*\\.jar", name); }/*from ww w .j a va2s .c om*/ return false; }
From source file:org.cloudfoundry.ide.eclipse.internal.server.core.CloudUtil.java
License:Open Source License
public static String getFramework(IProject project) { if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, DeploymentConstants.GRAILS_NATURE)) { return CloudApplication.GRAILS; }/*from w ww . j a va 2 s .c o m*/ // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() && project.getFile("application.properties").exists()) { return CloudApplication.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return DeploymentConstants.LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return DeploymentConstants.LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(new Status(IStatus.WARNING, CloudFoundryPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudApplication.SPRING; } if (foundSpringLibrary) { return CloudApplication.SPRING; } } } return null; }
From source file:org.cloudfoundry.ide.eclipse.internal.server.core.standalone.StandaloneRuntimeResolver.java
License:Open Source License
/** * Returns either test sources, or non-test sources, based on a flag * setting. If nothing is found, returns empty list. *//* w w w . j av a 2s . c om*/ protected Collection<IClasspathEntry> getSourceEntries(boolean istest) { try { IClasspathEntry[] rawEntries = javaProject.getRawClasspath(); if (rawEntries != null) { Collection<IClasspathEntry> sourceEntries = new HashSet<IClasspathEntry>(); for (IClasspathEntry entry : rawEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path != null) { boolean isTestSource = isTestSource(path.toOSString()); if ((istest && isTestSource) || (!istest && !isTestSource)) { sourceEntries.add(entry); } } } } return sourceEntries; } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } return Collections.emptyList(); }
From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.wizards.CloudFoundryApplicationWizardPage.java
License:Open Source License
private static String getFramework(ApplicationModule module) { if (module != null && module.getLocalModule() != null) { IProject project = module.getLocalModule().getProject(); if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, GRAILS_NATURE)) { return CloudApplication.GRAILS; }//w w w . j av a 2 s.c om // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() && project.getFile("application.properties").exists()) { return CloudApplication.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { CloudFoundryServerUiPlugin.getDefault().getLog() .log(new Status(IStatus.WARNING, CloudFoundryServerUiPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudApplication.SPRING; } if (foundSpringLibrary) { return CloudApplication.SPRING; } } } } return CloudApplication.JAVA_WEB; }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.application.JavaWebApplicationDelegate.java
License:Open Source License
/** * Attempts to determine the framework based on the contents and nature of * the project. Returns null if no framework was determined. * @param project//from w w w. j a va 2 s . c o m * @return Framework type or null if framework was not determined. * @deprecated kept for reference as to how application type was being * determined from a Java project for legacy v1 CF servers. v2 Servers no * longer require a framework for an application, as frameworks have been * replaced with buildpacks. */ protected String getFramework(IProject project) { if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, CloudFoundryConstants.GRAILS_NATURE)) { return CloudFoundryConstants.GRAILS; } // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() //$NON-NLS-1$ && project.getFile("application.properties").exists()) { //$NON-NLS-1$ return CloudFoundryConstants.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return CloudFoundryConstants.LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return CloudFoundryConstants.LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { // Log the error but don't throw it again as there may be // other ways to detect the framework CloudFoundryPlugin.log(new Status(IStatus.WARNING, CloudFoundryPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); //$NON-NLS-1$ } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudFoundryConstants.SPRING; } if (foundSpringLibrary) { return CloudFoundryConstants.SPRING; } } } return null; }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.CloudFoundryProjectUtil.java
License:Open Source License
private static boolean hasBootDependencies(IClasspathEntry e) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = e.getPath(); String name = path.lastSegment(); return name.endsWith(".jar") && name.startsWith("spring-boot"); //$NON-NLS-1$ //$NON-NLS-2$ }//from ww w .j a v a2 s . c o m return false; }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.debug.DebugProvider.java
License:Open Source License
protected boolean containsDebugFiles(IJavaProject project) { try {//from w ww. j a v a 2s .co m IClasspathEntry[] entries = project.getResolvedClasspath(true); if (entries != null) { for (IClasspathEntry entry : entries) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath projectPath = project.getPath(); IPath relativePath = entry.getPath().makeRelativeTo(projectPath); IFolder folder = project.getProject().getFolder(relativePath); if (getFile(folder, ".profile.d", "ngrok.sh") != null) {//$NON-NLS-1$ //$NON-NLS-2$ return true; } } } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } catch (CoreException ce) { CloudFoundryPlugin.logError(ce); } return false; }
From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.application.StandaloneRuntimeResolver.java
License:Open Source License
/** * Returns either test sources, or non-test sources, based on a flag * setting. If nothing is found, returns empty list. *//*from w w w . jav a 2 s .c o m*/ protected Collection<IClasspathEntry> getSourceEntries(boolean istest) { try { IClasspathEntry[] rawEntries = javaProject.getRawClasspath(); if (rawEntries != null) { Collection<IClasspathEntry> sourceEntries = new HashSet<IClasspathEntry>(); for (IClasspathEntry entry : rawEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path != null) { boolean isTestSource = isTestSource(path.toOSString()); if ((istest && isTestSource) || (!istest && !isTestSource)) { sourceEntries.add(entry); } } } } return sourceEntries; } } catch (JavaModelException e) { CloudFoundryPlugin.log(e); } return Collections.emptyList(); }
From source file:org.codecover.eclipse.builder.CodeCoverCompilationParticipant.java
License:Open Source License
/** * This method is called for each project separately. *///w ww. j av a 2 s . c o m @Override public void buildStarting(BuildContext[] files, boolean isBatch) { if (files.length == 0) { return; } final IProject iProject = files[0].getFile().getProject(); final IPath projectFullPath = iProject.getFullPath(); final IPath projectLocation = iProject.getLocation(); final String projectFolderLocation = iProject.getLocation().toOSString(); final Queue<SourceTargetContainer> sourceTargetContainers = new LinkedList<SourceTargetContainer>(); final String instrumentedFolderLocation = CodeCoverPlugin.getDefault() .getPathToInstrumentedSources(iProject).toOSString(); // try to get all source folders final Queue<String> possibleSourceFolders = new LinkedList<String>(); try { final IJavaProject javaProject = JavaCore.create(iProject); for (IPackageFragmentRoot thisRoot : javaProject.getAllPackageFragmentRoots()) { IResource resource = thisRoot.getCorrespondingResource(); if (resource != null) { possibleSourceFolders.add(resource.getLocation().toOSString()); } } } catch (JavaModelException e) { eclipseLogger.fatal("JavaModelException in CompilationParticipant", e); //$NON-NLS-1$ return; } InstrumentableItemsManager instrumentableItemsManager = CodeCoverPlugin.getDefault() .getInstrumentableItemsManager(); TSContainerManager tscManager = CodeCoverPlugin.getDefault().getTSContainerManager(); // ////////////////////////////////////////////////////////////////////// // CREATE THE SOURCE TARGET CONTAINERS AND COPY THE UNINSTRUMENTED // FILES TO THE INSTRUMENTEDFOLDERLOCATION // ////////////////////////////////////////////////////////////////////// fillSourceTargetContainers(files, possibleSourceFolders, sourceTargetContainers, instrumentedFolderLocation, eclipseLogger, instrumentableItemsManager); // ////////////////////////////////////////////////////////////////////// // SEARCH IN ALL TSC OF THIS PROJECT IF A TSC CAN BE REUSED // ////////////////////////////////////////////////////////////////////// TestSessionContainer tsc; if (SEARCH_IN_ALL_TSC) { tsc = searchUseableTSC(iProject, files, instrumentableItemsManager, tscManager); } else { tsc = getUseableTSC(files, instrumentableItemsManager, tscManager); } // ////////////////////////////////////////////////////////////////////// // PREPARE INSTRUMENTATION // ////////////////////////////////////////////////////////////////////// InstrumenterDescriptor descriptor = new org.codecover.instrumentation.java15.InstrumenterDescriptor(); if (descriptor == null) { eclipseLogger.fatal("NullPointerException in CompilationParticipant"); //$NON-NLS-1$ } // check whether TSC's criteria match // with the selected criteria of the project if (tsc != null) { Set<Criterion> tscCriteria = tsc.getCriteria(); for (Criterion criterion : tscCriteria) { if (!CodeCoverPlugin.getCriterionSelectedState(iProject, criterion)) { // the TSC uses a criterion which is not selected for the project // therefore it can't be used tsc = null; } } // all selected criteria must be active for the TSC for (Criterion criterion : descriptor.getSupportedCriteria()) { if (CodeCoverPlugin.getCriterionSelectedState(iProject, criterion)) { if (!tscCriteria.contains(criterion)) { // the TSC doesn't use a criterion which is selected // for the project, this means we can't use the TSC tsc = null; } } } } eclipseLogger.debug("can reuse TSC: " + (tsc != null ? tsc : "no")); //$NON-NLS-1$ //$NON-NLS-2$ InstrumenterFactory factory = new DefaultInstrumenterFactory(); factory.setDescriptor(descriptor); // only instrument with the selected criteria for (Criterion criterion : descriptor.getSupportedCriteria()) { if (CodeCoverPlugin.getCriterionSelectedState(iProject, criterion)) { factory.addCriterion(criterion); } } factory.setCharset(DEFAULT_CHARSET_FOR_COMPILING); Instrumenter instrumenter = null; try { instrumenter = factory.getInstrumenter(); } catch (FactoryMisconfigurationException e) { eclipseLogger.fatal("FactoryMisconfigurationException in CompilationParticipant"); //$NON-NLS-1$ } // ////////////////////////////////////////////////////////////////////// // INSTRUMENT // ////////////////////////////////////////////////////////////////////// File rootFolder = new File(projectFolderLocation); File targetFolder = new File(instrumentedFolderLocation); MASTBuilder builder = new MASTBuilder(eclipseLogger); Map<String, Object> instrumenterDirectives = descriptor.getDefaultDirectiveValues(); CodeCoverPlugin plugin = CodeCoverPlugin.getDefault(); eclipseLogger.debug("Plugin: " + plugin); IPath coverageLogPath = CodeCoverPlugin.getDefault().getPathToCoverageLogs(iProject); coverageLogPath = coverageLogPath.append("coverage-log-file.clf"); //$NON-NLS-1$ instrumenterDirectives.put( org.codecover.instrumentation.java15.InstrumenterDescriptor.CoverageLogPathDirective.KEY, coverageLogPath.toOSString()); if (tsc != null) { // we can reuse the TSC instrumenterDirectives.put(org.codecover.instrumentation.UUIDDirective.KEY, tsc.getId()); } TestSessionContainer testSessionContainer; try { testSessionContainer = instrumenter.instrument(rootFolder, targetFolder, sourceTargetContainers, builder, instrumenterDirectives); } catch (InstrumentationIOException e) { eclipseLogger.fatal("InstrumentationIOException in CompilationParticipant", e); //$NON-NLS-1$ return; } catch (InstrumentationException e) { eclipseLogger.fatal("InstrumentationException in CompilationParticipant", e); //$NON-NLS-1$ return; } // ////////////////////////////////////////////////////////////////////// // SAVE TSC // ////////////////////////////////////////////////////////////////////// if (tsc == null) { // we have to create a new TSC try { tscManager.addTestSessionContainer(testSessionContainer, iProject, false, null, null); } catch (FileSaveException e) { eclipseLogger.fatal("FileSaveException in CompilationParticipant", e); //$NON-NLS-1$ } catch (TSCFileCreateException e) { eclipseLogger.fatal("CoreException in CompilationParticipant", e); //$NON-NLS-1$ } catch (FileLoadException e) { eclipseLogger.fatal("CoreException in CompilationParticipant", e); //$NON-NLS-1$ } catch (InvocationTargetException e) { // can't happen because we didn't pass a runnable eclipseLogger.warning("InvocationTargetException in CompilationParticipant", e); //$NON-NLS-1$ } catch (CancelException e) { eclipseLogger.warning("User canceled writing of" + //$NON-NLS-1$ " new test session container in" + //$NON-NLS-1$ " CompilationParticipant"); //$NON-NLS-1$ } } // TODO handle compilation errors IJavaProject javaProject = JavaCore.create(iProject); // set up classpath StringBuilder runCommand = new StringBuilder(1024); IClasspathEntry[] cpEntries; try { cpEntries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { eclipseLogger.fatal("JavaModelException in CompilationParticipant", e); //$NON-NLS-1$ return; } for (int i = 0; i < cpEntries.length; i++) { IClasspathEntry thisEntry = cpEntries[i]; if (thisEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (runCommand.length() == 0) { // this is the first entry -> create the class path option runCommand.append("-cp "); //$NON-NLS-1$ } else { // this is not the first -> we need a separator runCommand.append(File.pathSeparatorChar); } runCommand.append("\""); //$NON-NLS-1$ IPath itsIPath = thisEntry.getPath(); if (projectFullPath.isPrefixOf(itsIPath)) { itsIPath = itsIPath.removeFirstSegments(1); itsIPath = projectLocation.append(itsIPath); } runCommand.append(itsIPath.toOSString()); runCommand.append("\""); //$NON-NLS-1$ } } // check java version related options String targetVersion = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); runCommand.append(" -target "); //$NON-NLS-1$ runCommand.append(targetVersion); String sourceVersion = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); runCommand.append(" -source "); //$NON-NLS-1$ runCommand.append(sourceVersion); // no warnings runCommand.append(" -nowarn"); //$NON-NLS-1$ // use the default charset for the encoding // all files have been instrumented or copied using this charset runCommand.append(" -encoding "); //$NON-NLS-1$ runCommand.append(DEFAULT_CHARSET_FOR_COMPILING.toString()); // the directory to compile // put the path in "", because the commandline tokenizes this path runCommand.append(" \""); //$NON-NLS-1$ runCommand.append(instrumentedFolderLocation); runCommand.append("\""); //$NON-NLS-1$ eclipseLogger.debug("I run this compile command now:\n" + runCommand); //$NON-NLS-1$ StringWriter out = new StringWriter(); StringWriter err = new StringWriter(); boolean result; result = org.eclipse.jdt.internal.compiler.batch.Main.compile(runCommand.toString(), new PrintWriter(out), new PrintWriter(err)); eclipseLogger.debug("ECJ Output: " + out.toString()); //$NON-NLS-1$ eclipseLogger.debug("ECJ Error Output: " + err.toString()); //$NON-NLS-1$ if (!result) { eclipseLogger.fatal("An error occured when trying to compile the instrumented sources."); //$NON-NLS-1$ } super.buildStarting(files, isBatch); }