List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Search the Ceylon classpath containers within the specified Java project * /*ww w .ja v a 2 s . c o m*/ * @param javaProject * the project to search into * @return the Ivy classpath container if found */ public static List<CeylonClasspathContainer> getCeylonClasspathContainers(IJavaProject javaProject) { List<CeylonClasspathContainer> containers = new ArrayList<CeylonClasspathContainer>(); if (FakeProjectManager.isFake(javaProject) || !javaProject.exists()) { return containers; } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (isCeylonClasspathContainer(path)) { IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject); if (cp instanceof CeylonClasspathContainer) { containers.add((CeylonClasspathContainer) cp); } } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen e.printStackTrace(); } return containers; }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Search the Ivy classpath entry within the specified Java project with the specific path * /*from w w w. j a v a 2 s .c o m*/ * @param containerPath * the path of the container * @param javaProject * the project to search into * @return the Ivy classpath container if found, otherwise return <code>null</code> */ public static IClasspathEntry getCeylonClasspathEntry(IPath containerPath, IJavaProject javaProject) { if (FakeProjectManager.isFake(javaProject) || !javaProject.exists()) { return null; } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (containerPath.equals(entry.getPath())) { return entry; } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen e.printStackTrace(); } return null; }
From source file:com.redhat.ceylon.eclipse.core.launch.CeylonMainTab.java
License:Open Source License
/** * Show a dialog that lists all main types *//*from w w w.ja v a 2 s . com*/ protected void handleSearchButtonSelected() { IJavaProject project = getJavaProject(); IJavaElement[] elements = null; if ((project == null) || !project.exists()) { IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); if (model != null) { try { elements = model.getJavaProjects(); } catch (JavaModelException e) { JDIDebugUIPlugin.log(e); } } } else { elements = new IJavaElement[] { project }; } if (elements == null) { elements = new IJavaElement[] {}; } int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); MainMethodSearchEngine engine = new MainMethodSearchEngine(); IType[] types = null; try { types = engine.searchMainMethods(getLaunchConfigurationDialog(), searchScope, false); } catch (InvocationTargetException e) { setErrorMessage(e.getMessage()); return; } catch (InterruptedException e) { setErrorMessage(e.getMessage()); return; } DebugTypeSelectionDialog mmsd = new DebugTypeSelectionDialog(getShell(), types, LauncherMessages.JavaMainTab_Choose_Main_Type_11); if (mmsd.open() == Window.CANCEL) { return; } Object[] results = mmsd.getResult(); IType type = (IType) results[0]; if (type != null) { fMainText.setText(type.getFullyQualifiedName()); fProjText.setText(type.getJavaProject().getElementName()); } }
From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java
License:Open Source License
private void validateBuild(IBuild build) { IBuildEntry binIncludes = null;//from w w w. j a v a 2s . c om IBuildEntry binExcludes = null; IBuildEntry srcIncludes = null; IBuildEntry srcExcludes = null; IBuildEntry jarsExtra = null; IBuildEntry bundleList = null; IBuildEntry javacSource = null; IBuildEntry javacTarget = null; IBuildEntry jreCompilationProfile = null; IBuildEntry javaProjectWarnings = null; ArrayList javacWarnings = new ArrayList(); ArrayList javacErrors = new ArrayList(); ArrayList sourceEntries = new ArrayList(1); ArrayList sourceEntryKeys = new ArrayList(1); ArrayList outputEntries = new ArrayList(1); Map encodingEntries = new HashMap(); IBuildEntry[] entries = build.getBuildEntries(); for (int i = 0; i < entries.length; i++) { String name = entries[i].getName(); if (entries[i].getTokens().length == 0) prepareError(name, null, MDECoreMessages.BuildErrorReporter_emptyEntry, MDEMarkerFactory.B_REMOVAL, MDEMarkerFactory.CAT_FATAL); else if (name.equals(PROPERTY_BIN_INCLUDES)) binIncludes = entries[i]; else if (name.equals(PROPERTY_BIN_EXCLUDES)) binExcludes = entries[i]; else if (name.equals(PROPERTY_SRC_INCLUDES)) srcIncludes = entries[i]; else if (name.equals(PROPERTY_SRC_EXCLUDES)) srcExcludes = entries[i]; else if (name.equals(PROPERTY_JAVAC_SOURCE)) javacSource = entries[i]; else if (name.equals(PROPERTY_JAVAC_TARGET)) javacTarget = entries[i]; else if (name.equals(PROPERTY_PROJECT_SETTINGS)) javaProjectWarnings = entries[i]; else if (name.equals(PROPERTY_JRE_COMPILATION_PROFILE)) jreCompilationProfile = entries[i]; else if (name.startsWith(PROPERTY_JAVAC_WARNINGS_PREFIX)) javacWarnings.add(entries[i]); else if (name.startsWith(PROPERTY_JAVAC_ERRORS_PREFIX)) javacErrors.add(entries[i]); else if (name.startsWith(PROPERTY_SOURCE_PREFIX)) sourceEntries.add(entries[i]); else if (name.startsWith(PROPERTY_OUTPUT_PREFIX)) outputEntries.add(entries[i]); else if (name.startsWith(PROPERTY_JAVAC_DEFAULT_ENCODING_PREFIX)) encodingEntries.put(entries[i].getName(), entries[i].getTokens()[0]); else if (name.equals(PROPERTY_JAR_EXTRA_CLASSPATH)) jarsExtra = entries[i]; else if (name.equals(IBuildEntry.SECONDARY_DEPENDENCIES)) bundleList = entries[i]; else if (name.equals(PROPERTY_CUSTOM)) { String[] tokens = entries[i].getTokens(); if (tokens.length == 1 && tokens[0].equalsIgnoreCase("true")) //$NON-NLS-1$ // nothing to validate in custom builds return; } // non else if statement to catch all names if (name.startsWith(PROPERTY_SOURCE_PREFIX)) sourceEntryKeys.add(entries[i].getName()); } // validation not relying on build flag if (fClasspathSeverity != CompilerFlags.IGNORE) { if (bundleList != null) validateDependencyManagement(bundleList); } if (jarsExtra != null) validateJarsExtraClasspath(jarsExtra); validateIncludes(binIncludes, sourceEntryKeys, fBinInclSeverity); validateIncludes(binExcludes, sourceEntryKeys, fBinInclSeverity); validateIncludes(srcIncludes, sourceEntryKeys, fSrcInclSeverity); validateIncludes(srcExcludes, sourceEntryKeys, fSrcInclSeverity); validateSourceFoldersInSrcIncludes(srcIncludes); try { IJavaProject jp = JavaCore.create(fProject); if (jp.exists()) { IClasspathEntry[] cpes = jp.getRawClasspath(); validateMissingLibraries(sourceEntryKeys, cpes); validateSourceEntries(sourceEntries, srcExcludes, cpes); SourceEntryErrorReporter srcEntryErrReporter = new SourceEntryErrorReporter(fFile, build); srcEntryErrReporter.initialize(sourceEntries, outputEntries, cpes, fProject); srcEntryErrReporter.validate(); ArrayList problems = srcEntryErrReporter.getProblemList(); for (int i = 0; i < problems.size(); i++) { if (!fProblemList.contains(problems.get(i))) { fProblemList.add(problems.get(i)); } } } } catch (JavaModelException e) { } validateMissingSourceInBinIncludes(binIncludes, sourceEntryKeys, build); validateBinIncludes(binIncludes); validateExecutionEnvironment(javacSource, javacTarget, jreCompilationProfile, javacWarnings, javacErrors, getSourceLibraries(sourceEntries)); validateJavaCompilerSettings(javaProjectWarnings); }
From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java
License:Open Source License
/** * Matches the javacSource, javacTarget, javacWarnings, javacErrors and jre.compilation.prile entries in build.properties with the * project specific Java Compiler properties and reports the errors found. * /*from w ww .j a v a2 s . c o m*/ * @param javacSourceEntry * @param javacTargetEntry * @param jreCompilationProfileEntry * @param javacWarningsEntries * @param javacErrorsEntries * @param libraryNames list of library names (javacWarnings/javacErrors require an entry for each source library) */ private void validateExecutionEnvironment(IBuildEntry javacSourceEntry, IBuildEntry javacTargetEntry, IBuildEntry jreCompilationProfileEntry, ArrayList javacWarningsEntries, ArrayList javacErrorsEntries, List libraryNames) { // if there is no source to compile, don't worry about compiler settings IJavaProject project = JavaCore.create(fProject); if (project.exists()) { IClasspathEntry[] classpath = null; try { classpath = project.getRawClasspath(); } catch (JavaModelException e) { MDECore.log(e); return; } boolean source = false; for (int i = 0; i < classpath.length; i++) { IClasspathEntry cpe = classpath[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { source = true; } } if (!source) { return; } String projectComplianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, false); if (projectComplianceLevel != null) { IMonitorModelBase model = MonitorRegistry.findModel(fProject); String[] execEnvs = null; if (model != null) { BundleDescription bundleDesc = model.getBundleDescription(); if (bundleDesc != null) { execEnvs = bundleDesc.getExecutionEnvironments(); } } if (execEnvs == null || execEnvs.length == 0) { return; } //PDE Build uses top most entry to build the plug-in String execEnv = execEnvs[0]; String projectSourceCompatibility = project.getOption(JavaCore.COMPILER_SOURCE, true); String projectClassCompatibility = project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); if (projectComplianceLevel .equals(findMatchingEE(projectSourceCompatibility, projectClassCompatibility, false)) && execEnv.equals( findMatchingEE(projectSourceCompatibility, projectClassCompatibility, true))) { return; //The project compliance settings matches the BREE } Map defaultComplianceOptions = new HashMap(); JavaCore.setComplianceOptions(projectComplianceLevel, defaultComplianceOptions); //project compliance does not match the BREE String projectJavaCompatibility = findMatchingEE(projectSourceCompatibility, projectClassCompatibility, true); String message = null; if (projectJavaCompatibility != null) { if (jreCompilationProfileEntry == null) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JRE_COMPILATION_PROFILE, MDECoreMessages.BuildErrorReporter_CompilercomplianceLevel); prepareError(PROPERTY_JRE_COMPILATION_PROFILE, projectJavaCompatibility, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } else { if (!projectJavaCompatibility.equalsIgnoreCase(jreCompilationProfileEntry.getTokens()[0])) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JRE_COMPILATION_PROFILE, MDECoreMessages.BuildErrorReporter_CompilercomplianceLevel); prepareError(PROPERTY_JRE_COMPILATION_PROFILE, projectJavaCompatibility, message, MDEMarkerFactory.B_REPLACE, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } } } else { // Check source level setting if (projectSourceCompatibility.equals(defaultComplianceOptions.get(JavaCore.COMPILER_SOURCE))) { if (javacSourceEntry != null) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_BuildEntryNotRequiredMatchesDefault, PROPERTY_JAVAC_SOURCE, MDECoreMessages.BuildErrorReporter_SourceCompatibility); prepareError(PROPERTY_JAVAC_SOURCE, null, message, MDEMarkerFactory.B_REMOVAL, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } } else { if (javacSourceEntry == null) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JAVAC_SOURCE, MDECoreMessages.BuildErrorReporter_SourceCompatibility); prepareError(PROPERTY_JAVAC_SOURCE, projectSourceCompatibility, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } else { if (!projectSourceCompatibility.equalsIgnoreCase(javacSourceEntry.getTokens()[0])) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JAVAC_SOURCE, MDECoreMessages.BuildErrorReporter_SourceCompatibility); prepareError(PROPERTY_JAVAC_SOURCE, projectSourceCompatibility, message, MDEMarkerFactory.B_REPLACE, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } } } // Check target level setting if (projectClassCompatibility .equals(defaultComplianceOptions.get(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM))) { if (javacTargetEntry != null) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_BuildEntryNotRequiredMatchesDefault, PROPERTY_JAVAC_TARGET, MDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility); prepareError(PROPERTY_JAVAC_TARGET, null, message, MDEMarkerFactory.B_REMOVAL, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } } else { if (javacTargetEntry == null) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JAVAC_TARGET, MDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility); prepareError(PROPERTY_JAVAC_TARGET, projectClassCompatibility, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } else { if (!projectClassCompatibility.equalsIgnoreCase(javacTargetEntry.getTokens()[0])) { message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JAVAC_TARGET, MDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility); prepareError(PROPERTY_JAVAC_TARGET, projectClassCompatibility, message, MDEMarkerFactory.B_REPLACE, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } } } } boolean warnForJavacWarnings = message != null || javacSourceEntry != null || javacTargetEntry != null || jreCompilationProfileEntry != null; if (warnForJavacWarnings == false) { return; } checkJavaComplianceSettings(projectComplianceLevel, javacWarningsEntries, javacErrorsEntries, libraryNames); } } }
From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java
License:Open Source License
/** * Matches the javacWarnings and javacErrors entries in build.properties with the * project specific Java compliance properties and reports the errors found. Since java * compiler settings are set on a per project basis, any special javacWarnings/javacErrors * must be set for each library./* w w w. j a va 2 s.co m*/ * * @param complianceLevel the compliance level to check settings against, used to get default values * @param javacWarningsEntries list of build entries with the java compiler warnings prefix javacWarnings. * @param javacErrorsEntries list of build entries with the java compiler errors prefix javacErrors. * @param libraryNames list of String library names */ private void checkJavaComplianceSettings(String complianceLevel, ArrayList javacWarningsEntries, ArrayList javacErrorsEntries, List libraryNames) { List complianceWarnSettings = new ArrayList(3); List complianceErrorSettings = new ArrayList(3); IJavaProject project = JavaCore.create(fProject); if (project.exists()) { Map defaultComplianceOptions = new HashMap(); JavaCore.setComplianceOptions(complianceLevel, defaultComplianceOptions); //look for assertIdentifier and enumIdentifier entries in javacWarnings. If any is present let it be, if not warn. String assertIdentifier = project.getOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, false); String defaultAssert = (String) defaultComplianceOptions.get(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER); if (assertIdentifier != null && !assertIdentifier.equalsIgnoreCase(defaultAssert)) { if (JavaCore.ERROR.equalsIgnoreCase(assertIdentifier)) { complianceErrorSettings.add(ASSERT_IDENTIFIER); } else if (JavaCore.WARNING.equalsIgnoreCase(assertIdentifier)) { complianceWarnSettings.add(ASSERT_IDENTIFIER); } } String enumIdentifier = project.getOption(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, false); String defaultEnum = (String) defaultComplianceOptions.get(JavaCore.COMPILER_PB_ENUM_IDENTIFIER); if (enumIdentifier != null && !enumIdentifier.equalsIgnoreCase(defaultEnum)) { if (JavaCore.ERROR.equalsIgnoreCase(enumIdentifier)) { complianceErrorSettings.add(ENUM_IDENTIFIER); } else if (JavaCore.WARNING.equalsIgnoreCase(enumIdentifier)) { complianceWarnSettings.add(ENUM_IDENTIFIER); } } // If a warnings entry is required, make sure there is one for each library with the correct content if (complianceWarnSettings.size() > 0) { for (Iterator iterator = libraryNames.iterator(); iterator.hasNext();) { String libName = (String) iterator.next(); IBuildEntry matchingEntry = null; for (Iterator iterator2 = javacWarningsEntries.iterator(); iterator2.hasNext();) { IBuildEntry candidate = (IBuildEntry) iterator2.next(); if (candidate.getName().equals(PROPERTY_JAVAC_WARNINGS_PREFIX + libName)) { matchingEntry = candidate; break; } } if (matchingEntry == null) { String missingTokens = ""; //$NON-NLS-1$ for (Iterator iterator2 = complianceWarnSettings.iterator(); iterator2.hasNext();) { String currentIdentifier = (String) iterator2.next(); missingTokens = join(missingTokens, '-' + currentIdentifier); } String message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JAVAC_WARNINGS_PREFIX + libName); prepareError(PROPERTY_JAVAC_WARNINGS_PREFIX + libName, missingTokens, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } else { String missingTokens = ""; //$NON-NLS-1$ for (Iterator iterator2 = complianceWarnSettings.iterator(); iterator2.hasNext();) { String currentIdentifier = (String) iterator2.next(); if (!matchingEntry.contains(currentIdentifier) && !matchingEntry.contains('+' + currentIdentifier) && !matchingEntry.contains('-' + currentIdentifier)) { join(missingTokens, '-' + currentIdentifier); } } if (missingTokens.length() > 0) { String message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JAVAC_WARNINGS_PREFIX + libName); prepareError(PROPERTY_JAVAC_WARNINGS_PREFIX + libName, missingTokens, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } } } } // If a warnings entry is required, make sure there is one for each library with the correct content if (complianceErrorSettings.size() > 0) { for (Iterator iterator = libraryNames.iterator(); iterator.hasNext();) { String libName = (String) iterator.next(); IBuildEntry matchingEntry = null; for (Iterator iterator2 = javacErrorsEntries.iterator(); iterator2.hasNext();) { IBuildEntry candidate = (IBuildEntry) iterator2.next(); if (candidate.getName().equals(PROPERTY_JAVAC_ERRORS_PREFIX + libName)) { matchingEntry = candidate; break; } } if (matchingEntry == null) { String missingTokens = ""; //$NON-NLS-1$ for (Iterator iterator2 = complianceErrorSettings.iterator(); iterator2.hasNext();) { String currentIdentifier = (String) iterator2.next(); missingTokens = join(missingTokens, '-' + currentIdentifier); } String message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, PROPERTY_JAVAC_ERRORS_PREFIX + libName); prepareError(PROPERTY_JAVAC_ERRORS_PREFIX + libName, missingTokens, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } else { String missingTokens = ""; //$NON-NLS-1$ for (Iterator iterator2 = complianceErrorSettings.iterator(); iterator2.hasNext();) { String currentIdentifier = (String) iterator2.next(); if (!matchingEntry.contains(currentIdentifier) && !matchingEntry.contains('+' + currentIdentifier) && !matchingEntry.contains('-' + currentIdentifier)) { missingTokens = join(missingTokens, '-' + currentIdentifier); } } if (missingTokens.length() > 0) { String message = NLS.bind( MDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, PROPERTY_JAVAC_ERRORS_PREFIX + libName); prepareError(PROPERTY_JAVAC_ERRORS_PREFIX + libName, missingTokens, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaComplianceSeverity, MDEMarkerFactory.CAT_EE); } } } } } }
From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java
License:Open Source License
private void validateSourceFoldersInSrcIncludes(IBuildEntry includes) { if (includes == null) return;// w ww .ja v a 2 s . co m List sourceFolderList = new ArrayList(0); try { IJavaProject javaProject = JavaCore.create(fProject); if (javaProject.exists()) { IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true); for (int index = 0; index < classPathEntries.length; index++) { if (classPathEntries[index].getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceFolderList.add(classPathEntries[index].getPath()); } } } } catch (JavaModelException e) { //do nothing } List reservedTokens = Arrays.asList(RESERVED_NAMES); String[] tokens = includes.getTokens(); for (int i = 0; i < tokens.length; i++) { IResource res = fProject.findMember(tokens[i]); if (res == null) continue; String errorMessage = null; if (sourceFolderList.contains(res.getFullPath())) { errorMessage = MDECoreMessages.BuildErrorReporter_srcIncludesSourceFolder; } else if (tokens[i].startsWith(".") //$NON-NLS-1$ || reservedTokens.contains(res.getName().toString().toLowerCase())) { errorMessage = NLS.bind(MDECoreMessages.BuildErrorReporter_srcIncludesSourceFolder1, res.getName()); } if (errorMessage != null) { prepareError(includes.getName(), tokens[i], errorMessage, MDEMarkerFactory.B_REMOVAL, fSrcInclSeverity, MDEMarkerFactory.CAT_OTHER); } } }
From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java
License:Open Source License
/** * Checks that if the project has java compiler settings that build.properties contains a use project settings * entry so that the compiler picks up the settings using the .pref file. * /*from ww w . ja v a2 s . c om*/ * @param useJavaProjectSettings a build entry for using the project's compiler warning preferences file */ private void validateJavaCompilerSettings(IBuildEntry useJavaProjectSettings) { // Check if the project has compiler warnings set IJavaProject project = JavaCore.create(fProject); if (project.exists()) { Map options = project.getOptions(false); // If project specific options are turned on, all options will be stored. Only need to check if at least one compiler option is set. Currently using the second option on the property page. if (options.containsKey(JavaCore.COMPILER_PB_INDIRECT_STATIC_ACCESS)) { if (useJavaProjectSettings != null) { boolean entryCorrect = false; String[] tokens = useJavaProjectSettings.getTokens(); if (tokens != null && tokens.length == 1) { if (Boolean.TRUE.toString().equalsIgnoreCase(tokens[0])) { // True is valid if the bundle root is the default (the project) entryCorrect = fProject.equals(PDEProject.getBundleRoot(fProject)); } else { IPath prefFile = null; prefFile = new Path(tokens[0]); if (prefFile.isAbsolute()) { entryCorrect = prefFile.toFile().exists(); } else { IContainer root = PDEProject.getBundleRoot(fProject); entryCorrect = root.getFile(prefFile).exists(); } } } if (!entryCorrect) { String token = null; String message = null; IContainer root = PDEProject.getBundleRoot(fProject); if (fProject.equals(root)) { // Default project root, just use 'true' token = Boolean.TRUE.toString(); message = NLS.bind(MDECoreMessages.BuildErrorReporter_buildEntryMissingValidPath, PROPERTY_PROJECT_SETTINGS); } else { // Non default bundle root, make a relative path IPath prefFile = fProject.getFullPath().append(".settings") //$NON-NLS-1$ .append(JavaCore.PLUGIN_ID + ".prefs"); //$NON-NLS-1$ prefFile = prefFile.makeRelativeTo(root.getFullPath()); token = prefFile.toString(); message = NLS.bind( MDECoreMessages.BuildErrorReporter_buildEntryMissingValidRelativePath, PROPERTY_PROJECT_SETTINGS); } prepareError(PROPERTY_PROJECT_SETTINGS, token, message, MDEMarkerFactory.B_REPLACE, fJavaCompilerSeverity, MDEMarkerFactory.CAT_EE); } } else { String token = null; IContainer root = PDEProject.getBundleRoot(fProject); if (fProject.equals(root)) { // Default project root, just use 'true' token = Boolean.TRUE.toString(); } else { // Non default bundle root, make a relative path IPath prefFile = fProject.getFullPath().append(".settings") //$NON-NLS-1$ .append(JavaCore.PLUGIN_ID + ".prefs"); //$NON-NLS-1$ prefFile = prefFile.makeRelativeTo(root.getFullPath()); token = prefFile.toString(); } String message = NLS.bind( MDECoreMessages.BuildErrorReporter_buildEntryMissingProjectSpecificSettings, PROPERTY_PROJECT_SETTINGS); prepareError(PROPERTY_PROJECT_SETTINGS, token, message, MDEMarkerFactory.B_JAVA_ADDDITION, fJavaCompilerSeverity, MDEMarkerFactory.CAT_EE); } } else if (useJavaProjectSettings != null) { String message = NLS.bind(MDECoreMessages.BuildErrorReporter_buildEntryInvalidWhenNoProjectSettings, PROPERTY_PROJECT_SETTINGS); prepareError(PROPERTY_PROJECT_SETTINGS, null, message, MDEMarkerFactory.B_REMOVAL, fJavaCompilerSeverity, MDEMarkerFactory.CAT_EE); } } }
From source file:com.siteview.mde.internal.core.builders.BundleErrorReporter.java
License:Open Source License
private void validateRequiredExecutionEnvironment() { int sev = CompilerFlags.getFlag(fProject, CompilerFlags.P_INCOMPATIBLE_ENV); if (sev == CompilerFlags.IGNORE) return;/*from ww w. jav a 2 s . c o m*/ BundleDescription desc = fModel.getBundleDescription(); if (desc == null) return; // if we aren't a java project, let's not check for a BREE try { if (!fProject.hasNature(JavaCore.NATURE_ID)) return; } catch (CoreException e) { return; } String[] bundleEnvs = desc.getExecutionEnvironments(); if (bundleEnvs == null || bundleEnvs.length == 0) { // No EE specified IJavaProject javaProject = JavaCore.create(fProject); // See if the project has an EE classpath entry if (javaProject.exists()) { try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath currentPath = entries[i].getPath(); if (JavaRuntime.newDefaultJREContainerPath().matchingFirstSegments(currentPath) > 0) { String eeId = JavaRuntime.getExecutionEnvironmentId(currentPath); if (eeId != null) { IMarker marker = report( MDECoreMessages.BundleErrorReporter_noExecutionEnvironmentSet, 1, sev, MDEMarkerFactory.M_EXECUTION_ENVIRONMENT_NOT_SET, MDEMarkerFactory.CAT_EE); addMarkerAttribute(marker, "ee_id", eeId); //$NON-NLS-1$ return; } } } } } catch (JavaModelException e) { MDECore.log(e); } } // If no EE classpath entry, get a matching EE for the project JRE (or the default JRE) IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager() .getExecutionEnvironments(); IVMInstall vm = JavaRuntime.getDefaultVMInstall(); if (javaProject.exists()) { try { vm = JavaRuntime.getVMInstall(javaProject); } catch (CoreException e) { MDECore.log(e); } } if (vm != null) { for (int i = 0; i < systemEnvs.length; i++) { // Get strictly compatible EE for the default VM if (systemEnvs[i].isStrictlyCompatible(vm)) { IMarker marker = report(MDECoreMessages.BundleErrorReporter_noExecutionEnvironmentSet, 1, sev, MDEMarkerFactory.M_EXECUTION_ENVIRONMENT_NOT_SET, MDEMarkerFactory.CAT_EE); addMarkerAttribute(marker, "ee_id", systemEnvs[i].getId()); //$NON-NLS-1$ break; } } } return; } IHeader header = getHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); if (header == null) return; IExecutionEnvironment env = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(bundleEnvs[0]); if (env != null) { IJavaProject jproject = JavaCore.create(fProject); IClasspathEntry[] entries; try { entries = jproject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() != IClasspathEntry.CPE_CONTAINER) continue; IPath currentPath = entries[i].getPath(); if (JavaRuntime.newDefaultJREContainerPath().matchingFirstSegments(currentPath) == 0) continue; IPath validPath = JavaRuntime.newJREContainerPath(env); if (!validPath.equals(currentPath)) { // Check if the user is using a perfect match JRE IVMInstall vm = JavaRuntime.getVMInstall(currentPath); if (vm == null || !env.isStrictlyCompatible(vm)) { report(NLS.bind(MDECoreMessages.BundleErrorReporter_reqExecEnv_conflict, bundleEnvs[0]), getLine(header, bundleEnvs[0]), sev, MDEMarkerFactory.M_MISMATCHED_EXEC_ENV, MDEMarkerFactory.CAT_EE); } } } } catch (JavaModelException e) { } } IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager() .getExecutionEnvironments(); for (int i = 0; i < bundleEnvs.length; i++) { boolean found = false; for (int j = 0; j < systemEnvs.length; j++) { if (bundleEnvs[i].equals(systemEnvs[j].getId())) { found = true; break; } } if (!found) { report(NLS.bind(MDECoreMessages.BundleErrorReporter_reqExecEnv_unknown, bundleEnvs[i]), getLine(header, bundleEnvs[i]), sev, MDEMarkerFactory.M_UNKNOW_EXEC_ENV, MDEMarkerFactory.CAT_EE); break; } } }
From source file:com.siteview.mde.internal.core.exports.WorkspaceExportHelper.java
License:Open Source License
/** * Returns a map containing information associating libraries to the output locations the * workspace compiles them to. Uses information in the build.properties and the classpath. * The map will be of the following form: * String symbolic name > lib output map * The lib output map will be of the following form: * String lib name > Set of IPath output folders * * @param exportedItems the plugins or features being exported * @return a map of library output folders for each plugin in the workspace *///from w ww . jav a2 s . c o m public Map getWorkspaceOutputFolders(Object[] exportedItems) throws CoreException { IProject[] projects = getExportedWorkspaceProjects(exportedItems); Map result = new HashMap(projects.length); for (int i = 0; i < projects.length; i++) { IFile buildFile = PDEProject.getBuildProperties(projects[i]); if (buildFile.exists()) { IBuildModel buildModel = new WorkspaceBuildModel(buildFile); buildModel.load(); IJavaProject javaProject = JavaCore.create(projects[i]); if (javaProject.exists()) { Map modelOutput = getPluginOutputFolders(buildModel, javaProject); if (!modelOutput.isEmpty()) { IMonitorModelBase model = MDECore.getDefault().getModelManager().findModel(projects[i]); if (model != null) { result.put(model.getBundleDescription().getSymbolicName(), modelOutput); } } } } } return result; }