org.eclipse.pde.core_3.7.1.v20120103_r372

ldErrorReporter_BuildEntryNotRequiredMatchesDefault, "javacSource", PDECoreMessages.BuildErrorReporter_SourceCompatibility);
              prepareError("javacSource", null, message, 8197, fJavaComplianceSeverity, "ee");
            }
          }
          else if (javacSourceEntry == null)
          {
            message = NLS.bind(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, "javacSource", PDECoreMessages.BuildErrorReporter_SourceCompatibility);
            prepareError("javacSource", projectSourceCompatibility, message, 8199, fJavaComplianceSeverity, "ee");
          }
          else if (!projectSourceCompatibility.equalsIgnoreCase(javacSourceEntry.getTokens()[0]))
          {
            message = NLS.bind(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, "javacSource", PDECoreMessages.BuildErrorReporter_SourceCompatibility);
            prepareError("javacSource", projectSourceCompatibility, message, 8198, fJavaComplianceSeverity, "ee");
          }
          if (projectClassCompatibility.equals(defaultComplianceOptions.get("org.eclipse.jdt.core.compiler.codegen.targetPlatform")))
          {
            if (javacTargetEntry != null)
            {
              message = NLS.bind(PDECoreMessages.BuildErrorReporter_BuildEntryNotRequiredMatchesDefault, "javacTarget", PDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility);
              prepareError("javacTarget", null, message, 8197, fJavaComplianceSeverity, "ee");
            }
          }
          else if (javacTargetEntry == null)
          {
            message = NLS.bind(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, "javacTarget", PDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility);
            prepareError("javacTarget", projectClassCompatibility, message, 8199, fJavaComplianceSeverity, "ee");
          }
          else if (!projectClassCompatibility.equalsIgnoreCase(javacTargetEntry.getTokens()[0]))
          {
            message = NLS.bind(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, "javacTarget", PDECoreMessages.BuildErrorReporter_GeneratedClassFilesCompatibility);
            prepareError("javacTarget", projectClassCompatibility, message, 8198, fJavaComplianceSeverity, "ee");
          }
        }
        boolean warnForJavacWarnings = (message != null) || (javacSourceEntry != null) || (javacTargetEntry != null) || (jreCompilationProfileEntry != null);
        if (!warnForJavacWarnings) {
          return;
        }
        checkJavaComplianceSettings(projectComplianceLevel, javacWarningsEntries, javacErrorsEntries, libraryNames);
      }
    }
  }
  
  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);
      
      String assertIdentifier = project.getOption("org.eclipse.jdt.core.compiler.problem.assertIdentifier", false);
      String defaultAssert = (String)defaultComplianceOptions.get("org.eclipse.jdt.core.compiler.problem.assertIdentifier");
      if ((assertIdentifier != null) && (!assertIdentifier.equalsIgnoreCase(defaultAssert))) {
        if ("error".equalsIgnoreCase(assertIdentifier)) {
          complianceErrorSettings.add("assertIdentifier");
        } else if ("warning".equalsIgnoreCase(assertIdentifier)) {
          complianceWarnSettings.add("assertIdentifier");
        }
      }
      String enumIdentifier = project.getOption("org.eclipse.jdt.core.compiler.problem.enumIdentifier", false);
      String defaultEnum = (String)defaultComplianceOptions.get("org.eclipse.jdt.core.compiler.problem.enumIdentifier");
      if ((enumIdentifier != null) && (!enumIdentifier.equalsIgnoreCase(defaultEnum))) {
        if ("error".equalsIgnoreCase(enumIdentifier)) {
          complianceErrorSettings.add("enumIdentifier");
        } else if ("warning".equalsIgnoreCase(enumIdentifier)) {
          complianceWarnSettings.add("enumIdentifier");
        }
      }
      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("javacWarnings." + libName))
            {
              matchingEntry = candidate;
              break;
            }
          }
          if (matchingEntry == null)
          {
            String missingTokens = "";
            for (Iterator iterator2 = complianceWarnSettings.iterator(); iterator2.hasNext();)
            {
              String currentIdentifier = (String)iterator2.next();
              missingTokens = join(missingTokens, '-' + currentIdentifier);
            }
            String message = NLS.bind(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, "javacWarnings." + libName);
            prepareError("javacWarnings." + libName, missingTokens, message, 8199, fJavaComplianceSeverity, "ee");
          }
          else
          {
            String missingTokens = "";
            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(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, "javacWarnings." + libName);
              prepareError("javacWarnings." + libName, missingTokens, message, 8199, fJavaComplianceSeverity, "ee");
            }
          }
        }
      }
      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("javacErrors." + libName))
            {
              matchingEntry = candidate;
              break;
            }
          }
          if (matchingEntry == null)
          {
            String missingTokens = "";
            for (Iterator iterator2 = complianceErrorSettings.iterator(); iterator2.hasNext();)
            {
              String currentIdentifier = (String)iterator2.next();
              missingTokens = join(missingTokens, '-' + currentIdentifier);
            }
            String message = NLS.bind(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceMissingEntry, "javacErrors." + libName);
            prepareError("javacErrors." + libName, missingTokens, message, 8199, fJavaComplianceSeverity, "ee");
          }
          else
          {
            String missingTokens = "";
            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(PDECoreMessages.BuildErrorReporter_ProjectSpecificJavaComplianceDifferentToken, "javacErrors." + libName);
              prepareError("javacErrors." + libName, missingTokens, message, 8199, fJavaComplianceSeverity, "ee");
            }
          }
        }
      }
    }
  }
  
  private String findMatchingEE(String srcCompatibility, String clsCompatibility, boolean ee)
  {
    String executionEnv = null;
    String complaince = null;
    if (("1.1".equals(srcCompatibility)) && ("1.1".equals(clsCompatibility)))
    {
      executionEnv = "JRE-1.1";
      complaince = "1.1";
    }
    else if (("1.2".equals(srcCompatibility)) && ("1.1".equals(clsCompatibility)))
    {
      executionEnv = "J2SE-1.2";
      complaince = "1.2";
    }
    else if (("1.3".equals(srcCompatibility)) && ("1.1".equals(clsCompatibility)))
    {
      executionEnv = "J2SE-1.3";
      complaince = "1.3";
    }
    else if (("1.3".equals(srcCompatibility)) && ("1.2".equals(clsCompatibility)))
    {
      executionEnv = "J2SE-1.4";
      complaince = "1.4";
    }
    else if (("1.5".equals(srcCompatibility)) && ("1.5".equals(clsCompatibility)))
    {
      executionEnv = "J2SE-1.5";
      complaince = "1.5";
    }
    else if (("1.6".equals(srcCompatibility)) && ("1.6".equals(clsCompatibility)))
    {
      executionEnv = "JavaSE-1.6";
      complaince = "1.6";
    }
    else if (("1.7".equals(srcCompatibility)) && ("1.7".equals(clsCompatibility)))
    {
      executionEnv = "JavaSE-1.7";
      complaince = "1.7";
    }
    if (ee) {
      return executionEnv;
    }
    return complaince;
  }
  
  private void validateBinIncludes(IBuildEntry binIncludes)
  {
    if (PDEProject.getManifest(fProject).exists()) {
      validateBinIncludes(binIncludes, "META-INF/");
    }
    IFolder OSGinf = PDEProject.getOSGiInf(fProject);
    if (OSGinf.exists()) {
      try
      {
        if (OSGinf.members().length > 0) {
          validateBinIncludes(binIncludes, "OSGI-INF/");
        }
      }
      catch (CoreException localCoreException) {}
    }
    if (PDEProject.getFragmentXml(fProject).exists()) {
      validateBinIncludes(binIncludes, "fragment.xml");
    }
    if (PDEProject.getPluginXml(fProject).exists()) {
      validateBinIncludes(binIncludes, "plugin.xml");
    }
    IPluginModelBase model = PluginRegistry.findModel(fProject);
    if (model == null) {
      return;
    }
    if (((model instanceof IBundlePluginModelBase)) && (!(model instanceof IBundleFragmentModel)))
    {
      IBundleModel bm = ((IBundlePluginModelBase)model).getBundleModel();
      IManifestHeader mh = bm.getBundle().getManifestHeader("Bundle-Localization");
      IPath resourcePath = null;
      String entry = null;
      if ((mh == null) || (mh.getValue() == null))
      {
        resourcePath = new Path("OSGI-INF/l10n/bundle");
        entry = "OSGI-INF/l10n/bundle";
      }
      else
      {
        String localization = mh.getValue();
        int index = localization.lastIndexOf('/');
        if (index != -1)
        {
          entry = localization.substring(0, index + 1);
          resourcePath = new Path(entry);
        }
        else
        {
          entry = mh.getValue().concat(".properties");
          resourcePath = new Path(entry);
        }
      }
      if ((resourcePath != null) && (entry != null) && 
        (PDEProject.getBundleRoot(fProject).exists(resourcePath))) {
        validateBinIncludes(binIncludes, entry);
      }
    }
  }
  
  private void validateBinIncludes(IBuildEntry binIncludes, String key)
  {
    if (binIncludes == null) {
      return;
    }
    String[] tokens = binIncludes.getTokens();
    boolean exists = false;
    for (int i = 0; i < tokens.length; i++)
    {
      if (key.startsWith(tokens[i]))
      {
        exists = true;
        break;
      }
      IPath project = fFile.getProject().getLocation();
      if ((project != null) && (tokens[i] != null))
      {
        File file = project.toFile();
        File[] files = file.listFiles(new WildcardFilenameFilter(tokens[i]));
        for (int j = 0; j < files.length; j++) {
          if (files[j].toString().endsWith(key))
          {
            exists = true;
            break;
          }
        }
      }
    }
    if (!exists) {
      prepareError("bin.includes", key, NLS.bind(PDECoreMessages.BuildErrorReporter_binIncludesMissing, key), 8195, fBinInclSeverity, "fatal");
    }
  }
  
  private void validateJarsExtraClasspath(IBuildEntry javaExtra)
  {
    String platform = "platform:/plugin/";
    String[] tokens = javaExtra.getTokens();
    IPath projectPath = javaExtra.getModel().getUnderlyingResource().getProject().getLocation();
    for (int i = 0; i < tokens.length; i++)
    {
      boolean exists = true;
      if (tokens[i].startsWith(platform))
      {
        String path = tokens[i].substring(platform.length());
        int sep = path.indexOf('/');
        if (sep > -1)
        {
          IPluginModelBase model = PluginRegistry.findModel(path.substring(0, sep));
          if (model == null)
          {
            exists = false;
          }
          else
          {
            IResource resource = model.getUnderlyingResource();
            path = path.substring(sep + 1);
            if (resource == null)
            {
              String location = model.getInstallLocation();
              File external = new File(location);
              if (external.isDirectory())
              {
                IPath p = new Path(location).addTrailingSeparator().append(path);
                exists = new File(p.toOSString()).exists();
              }
              else
              {
                exists = false;
              }
            }
            else
            {
              exists = resource.getProject().findMember(path) != null;
            }
          }
        }
      }
      else
      {
        exists = projectPath.append(tokens[i]).toFile().exists();
      }
      if ((!exists) && (!startsWithAntVariable(tokens[i]))) {
        prepareError("jars.extra.classpath", tokens[i], NLS.bind(PDECoreMessages.BuildErrorReporter_cannotFindJar, tokens[i]), -1, fBuildSeverity, "");
      }
    }
  }
  
  private void validateMissingSourceInBinIncludes(IBuildEntry binIncludes, ArrayList sourceEntryKeys, IBuild build)
  {
    if (binIncludes == null) {
      return;
    }
    List pluginLibraryNames = new ArrayList(1);
    IPluginModelBase pluginModel = PluginRegistry.findModel(fProject);
    if (pluginModel != null)
    {
      IPluginLibrary[] pluginLibraries = pluginModel.getPluginBase().getLibraries();
      for (int i = 0; i < pluginLibraries.length; i++) {
        pluginLibraryNames.add(pluginLibraries[i].getName());
      }
    }
    if (!pluginLibraryNames.contains(".")) {
      pluginLibraryNames.add(".");
    }
    for (int i = 0; i < sourceEntryKeys.size(); i++)
    {
      String key = (String)sourceEntryKeys.get(i);
      if (!pluginLibraryNames.contains(key)) {
        return;
      }
      if ("source..".equals(key))
      {
        IBuildEntry entry = build.getEntry("source..");
        String[] tokens = entry.getTokens();
        if ((tokens.length == 1) && (tokens[0].equals("."))) {}
      }
      else
      {
        key = key.substring("source.".length());
        boolean found = false;
        String[] binIncludesTokens = binIncludes.getTokens();
        for (int j = 0; j < binIncludesTokens.length; j++)
        {
          Pattern pattern = PatternConstructor.createPattern(binIncludesTokens[j], false);
          if (pattern.matcher(key).matches()) {
            found = true;
          }
        }
        if (!found)
        {
          IPath path = new Path(key);
          if ((path.getFileExtension() == null) && 
            (!key.endsWith("/")))
          {
            key = key + "/";
            for (int j = 0; j < binIncludesTokens.length; j++)
            {
              Pattern pattern = PatternConstructor.createPattern(binIncludesTokens[j], false);
              if (pattern.matcher(key).matches()) {
                found = true;
              }
            }
          }
        }
        if (!found) {
          prepareError("bin.includes", key, NLS.bind(PDECoreMessages.BuildErrorReporter_binIncludesMissing, key), 8195, fBinInclSeverity, "fatal");
        }
      }
    }
  }
  
  private void validateMissingLibraries(ArrayList sourceEntryKeys, IClasspathEntry[] cpes)
  {
    boolean srcFolderExists = false;
    for (int j = 0; j < cpes.length; j++) {
      if (cpes[j].getEntryKind() == 3)
      {
        srcFolderExists = true;
        break;
      }
    }
    if (!srcFolderExists) {
      return;
    }
    IPluginModelBase model = PluginRegistry.findModel(fProject);
    if (model == null) {
      return;
    }
    if (((model instanceof IBundlePluginModelBase)) && (!(model instanceof IBundleFragmentModel)))
    {
      IBundleModel bm = ((IBundlePluginModelBase)model).getBundleModel();
      IManifestHeader mh = bm.getBundle().getManifestHeader("Bundle-ClassPath");
      if (((mh == null) || (mh.getValue() == null)) && 
        (!sourceEntryKeys.contains("source.."))) {
        prepareError("source..", null, PDECoreMessages.BuildErrorReporter_sourceMissing, -1, fSrcLibSeverity, "");
      }
    }
    IPluginLibrary[] libraries = model.getPluginBase().getLibraries();
    for (int i = 0; i < libraries.length; i++)
    {
      String libname = libraries[i].getName();
      if (libname.equals("."))
      {
        if (!sourceEntryKeys.contains("source.."))
        {
          prepareError("source..", null, PDECoreMessages.BuildErrorReporter_sourceMissing, -1, fSrcLibSeverity, "");
          continue;
        }
      }
      else {
        if (fProject.findMember(libname) != null) {
          continue;
        }
      }
      String sourceEntryKey = "source." + libname;
      if ((!sourceEntryKeys.contains(sourceEntryKey)) && (!containedInFragment(model.getBundleDescription(), libname))) {
        prepareError(sourceEntryKey, null, NLS.bind(PDECoreMessages.BuildErrorReporter_missingEntry, sourceEntryKey), 8195, "");
      }
    }
  }
  
  private boolean containedInFragment(BundleDescription description, String libname)
  {
    if (description == null) {
      return false;
    }
    BundleDescription[] fragments = description.getFragments();
    if (fragments == null) {
      return false;
    }
    for (int j = 0; j < fragments.length; j++)
    {
      IPluginModelBase fragmentModel = PluginRegistry.findModel(fragments[j]);
      if ((fragmentModel != null) && (fragmentModel.getUnderlyingResource() != null))
      {
        IProject project = fragmentModel.getUnderlyingResource().getProject();
        if (project.findMember(libname) != null) {
          return true;
        }
        try
        {
          IBuild build = ClasspathUtilCore.getBuild(fragmentModel);
          if (build == null) {
            continue;
          }
          IBuildEntry[] entries = build.getBuildEntries();
          for (int i = 0; i < entries.length; i++) {
            if (entries[i].getName().equals("source." + libname)) {
              return true;
            }
          }
          return false;
        }
        catch (CoreException localCoreException) {}
      }
      String location = fragments[j].getLocation();
      File external = new File(location);
      if (external.exists())
      {
        if (external.isDirectory())
        {
          IPath p = new Path(location).addTrailingSeparator().append(libname);
          return new File(p.toOSString()).exists();
        }
        return CoreUtility.jarContainsResource(external, libname, false);
      }
    }
    return false;
  }
  
  private void validateSourceEntries(ArrayList sourceEntries, IBuildEntry srcExcludes, IClasspathEntry[] cpes)
  {
    if ((sourceEntries == null) || (sourceEntries.size() == 0)) {
      return;
    }
    String[] unlisted = PDEBuilderHelper.getUnlistedClasspaths(sourceEntries, fProject, cpes);
    List excludeList = new ArrayList(0);
    if ((srcExcludes != null) && (srcExcludes.getTokens().length > 0)) {
      excludeList = Arrays.asList(srcExcludes.getTokens());
    }
    String name = ((IBuildEntry)sourceEntries.get(0)).getName();
    String message = PDECoreMessages.BuildErrorReporter_classpathEntryMissing1;
    if (sourceEntries.size() > 1)
    {
      name = "source..";
      message = PDECoreMessages.BuildErrorReporter_classpathEntryMissing;
    }
    for (int i = 0; i < unlisted.length; i++) {
      if ((unlisted[i] != null) && (!excludeList.contains(unlisted[i])))
      {
        BuildProblem error = prepareError(name, unlisted[i], NLS.bind(message, unlisted[i], name), 8195, fSrcLibSeverity, "");
        error.addExtraBuildEntryTokenAttribute("src.excludes", unlisted[i]);
      }
    }
  }
  
  private void validateSourceFoldersInSrcIncludes(IBuildEntry includes)
  {
    if (includes == null) {
      return;
    }
    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() == 3) {
            sourceFolderList.add(classPathEntries[index].getPath());
          }
        }
      }
    }
    catch (JavaModelException localJavaModelException) {}
    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)
      {
        String errorMessage = null;
        if (sourceFolderList.contains(res.getFullPath())) {
          errorMessage = PDECoreMessages.BuildErrorReporter_srcIncludesSourceFolder;
        } else if ((tokens[i].startsWith(".")) || (reservedTokens.contains(res.getName().toString().toLowerCase()))) {
          errorMessage = NLS.bind(PDECoreMessages.BuildErrorReporter_srcIncludesSourceFolder1, res.getName());
        }
        if (errorMessage != null) {
          prepareError(includes.getName(), tokens[i], errorMessage, 8197, fSrcInclSeverity, "");
        }
      }
    }
  }
  
  private void validateIncludes(IBuildEntry includes, ArrayList sourceIncludes, int severity)
  {
    if (includes == null) {
      return;
    }
    String[] tokens = includes.getTokens();
    for (int i = 0; i < tokens.length; i++)
    {
      String token = tokens[i].trim();
      if (token.indexOf("*") == -1) {
        if (!token.equals(".")) {
          if (!startsWithAntVariable(token))
          {
            IResource member = PDEProject.getBundleRoot(fProject).findMember(token);
            String message = null;
            int fixId = -1;
            if (member == null)
            {
              if (sourceIncludes.contains("source." + token)) {
                continue;
              }
              if (token.endsWith("/")) {
                message = NLS.bind(PDECoreMessages.BuildErrorReporter_missingFolder, token);
              } else {
                message = NLS.bind(PDECoreMessages.BuildErrorReporter_missingFile, token);
              }
              fixId = 8197;
            }
            else if ((token.endsWith("/")) && (!(member instanceof IFolder)))
            {
              message = NLS.bind(PDECoreMessages.BuildErrorReporter_entiresMustRefDirs, token);
              fixId = 8194;
            }
            else if ((!token.endsWith("/")) && (!(member instanceof IFile)))
            {
              message = NLS.bind(PDECoreMessages.BuildErrorReporter_dirsMustEndSlash, token);
              fixId = 8193;
            }
            if (message != null) {
              prepareError(includes.getName(), token, message, fixId, severity, "");
            }
          }
        }
      }
    }
  }
  
  private boolean startsWithAntVariable(String token)
  {
    int varStart = token.indexOf("${");
    return (varStart != -1) && (varStart < token.indexOf("}"));
  }
  
  private void validateDependencyManagement(IBuildEntry bundleList)
  {
    String[] bundles = bundleList.getTokens();
    for (int i = 0; i < bundles.length; i++) {
      if (PluginRegistry.findModel(bundles[i]) == null) {
        prepareError("additional.bundles", bundles[i], NLS.bind(PDECoreMessages.BuildErrorReporter_cannotFindBundle, bundles[i]), -1, fClasspathSeverity, "");
      }
    }
  }
  
  private void validateJavaCompilerSettings(IBuildEntry useJavaProjectSettings)
  {
    IJavaProject project = JavaCore.create(fProject);
    if (project.exists())
    {
      Map options = project.getOptions(false);
      if (options.containsKey("org.eclipse.jdt.core.compiler.problem.indirectStaticAccess"))
      {
        if (useJavaProjectSettings != null)
        {
          boolean entryCorrect = false;
          String[] tokens = useJavaProjectSettings.getTokens();
          if ((tokens != null) && (tokens.length == 1)) {
            if (Boolean.TRUE.toString().equalsIgnoreCase(tokens[0]))
            {
              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))
            {
              token = Boolean.TRUE.toString();
              message = NLS.bind(PDECoreMessages.BuildErrorReporter_buildEntryMissingValidPath, "javacProjectSettings");
            }
            else
            {
              IPath prefFile = fProject.getFullPath().append(".settings").append("org.eclipse.jdt.core.prefs");
              prefFile = prefFile.makeRelativeTo(root.getFullPath());
              token = prefFile.toString();
              message = NLS.bind(PDECoreMessages.BuildErrorReporter_buildEntryMissingValidRelativePath, "javacProjectSettings");
            }
            prepareError("javacProjectSettings", token, message, 8198, fJavaCompilerSeverity, "ee");
          }
        }
        else
        {
          String token = null;
          IContainer root = PDEProject.getBundleRoot(fProject);
          if (fProject.equals(root))
          {
            token = Boolean.TRUE.toString();
          }
          else
          {
            IPath prefFile = fProject.getFullPath().append(".settings").append("org.eclipse.jdt.core.prefs");
            prefFile = prefFile.makeRelativeTo(root.getFullPath());
            token = prefFile.toString();
          }
          String message = NLS.bind(PDECoreMessages.BuildErrorReporter_buildEntryMissingProjectSpecificSettings, "javacProjectSettings");
          prepareError("javacProjectSettings", token, message, 8199, fJavaCompilerSeverity, "ee");
        }
      }
      else if (useJavaProjectSettings != null)
      {
        String message = NLS.bind(PDECoreMessages.BuildErrorReporter_buildEntryInvalidWhenNoProjectSettings, "javacProjectSettings");
        prepareError("javacProjectSettings", null, message, 8197, fJavaCompilerSeverity, "ee");
      }
    }
  }
  
  private String join(String token1, String token2)
  {
    StringBuffer result = new StringBuffer();
    if ((token1 != null) && (token1.length() > 0)) {
      result.append(token1);
    }
    if ((token2 != null) && (token2.length() > 0))
    {
      if (result.length() > 0) {
        result.append(',');
      }
      result.append(token2);
    }
    return result.toString();
  }
  
  private BuildModel prepareTextBuildModel(IProgressMonitor monitor)
  {
    try
    {
      IDocument doc = createDocument(fFile);
      if (doc == null) {
        return null;
      }
      BuildModel bm = new BuildModel(doc, true);
      bm.load();
      if (!bm.isLoaded()) {
        return null;
      }
      return bm;
    }
    catch (CoreException e)
    {
      PDECore.log(e);
    }
    return null;
  }
  
  private void reportErrors(BuildModel bm)
  {
    if (bm == null) {
      return;
    }
    for (int i = 0; i < fProblemList.size(); i++)
    {
      BuildProblem bp = (BuildProblem)fProblemList.get(i);
      
      IBuildEntry buildEntry = bm.getBuild().getEntry(fEntryName);
      int lineNum;
      int lineNum;
      if ((buildEntry == null) || (fEntryName == null)) {
        lineNum = 1;
      } else {
        lineNum = getLineNumber(buildEntry, fEntryToken);
      }
      if (lineNum > 0)
      {
        IMarker marker = report(fMessage, lineNum, fFixId, fEntryName, fEntryToken, fSeverity, fCategory);
        if ((marker != null) && (attributes != null)) {
          for (Iterator iterator = attributes.keySet().iterator(); iterator.hasNext();)
          {
            String attribute = (String)iterator.next();
            try
            {
              marker.setAttribute(attribute, attributes.get(attribute));
            }
            catch (CoreException localCoreException) {}
          }
        }
      }
    }
  }
  
  private int getLineNumber(IBuildEntry ibe, String tokenString)
  {
    if (!(ibe instanceof BuildEntry)) {
      return 0;
    }
    BuildEntry be = (BuildEntry)ibe;
    IDocument doc = ((BuildModel)be.getModel()).getDocument();
    try
    {
      int buildEntryLineNumber = doc.getLineOfOffset(be.getOffset()) + 1;
      if (tokenString == null) {
        return buildEntryLineNumber;
      }
      String entry = doc.get(be.getOffset(), be.getLength());
      
      int valueIndex = entry.indexOf('=') + 1;
      if ((valueIndex == 0) || (valueIndex == entry.length())) {
        return buildEntryLineNumber;
      }
      entry = entry.substring(valueIndex);
      
      int entryTokenOffset = entry.indexOf(tokenString);
      if (entryTokenOffset == -1) {
        return buildEntryLineNumber;
      }
      entry = entry.substring(entryTokenOffset);
      int currOffset = be.getOffset() + valueIndex + entryTokenOffset;
      for (;;)
      {
        if (entry.charAt(0) == '\\')
        {
          currOffset++;
          entry = entry.substring(1);
        }
        int cci = entry.indexOf(',');
        if (cci == -1)
        {
          if (entry.trim().equals(tokenString)) {
            return doc.getLineOfOffset(currOffset + entry.indexOf(tokenString)) + 1;
          }
          return buildEntryLineNumber;
        }
        String ct = entry.substring(0, cci).trim();
        if (ct.equals(tokenString)) {
          return doc.getLineOfOffset(currOffset) + 1;
        }
        entry = entry.substring(++cci);
        currOffset += cci;
      }
      return 0;
    }
    catch (BadLocationException localBadLocationException) {}
  }
  
  protected BuildProblem prepareError(String name, String token, String message, int fixId, String category)
  {
    return prepareError(name, token, message, fixId, fBuildSeverity, category);
  }
  
  protected BuildProblem prepareError(String name, String token, String message, int fixId, int severity, String category)
  {
    BuildProblem bp = new BuildProblem(name, token, message, fixId, severity, category);
    for (int i = 0; i < fProblemList.size(); i++)
    {
      BuildProblem listed = (BuildProblem)fProblemList.get(i);
      if (listed.equals(bp))
      {
        if (attributes != null) {
          listed.addAttributes(attributes);
        }
        return listed;
      }
    }
    fProblemList.add(bp);
    return bp;
  }
  
  private IMarker report(String message, int line, int problemID, String buildEntry, String buildToken, int severity, String category)
  {
    IMarker marker = report(message, line, severity, problemID, category);
    if (marker != null) {
      try
      {
        marker.setAttribute("buildEntry.key", buildEntry);
        marker.setAttribute("buildEntry.tokenValue", buildToken);
      }
      catch (CoreException localCoreException) {}
    }
    return marker;
  }
  
  public boolean isCustomBuild()
  {
    WorkspaceBuildModel wbm = new WorkspaceBuildModel(fFile);
    IBuild build = wbm.getBuild();
    IBuildEntry entry = build.getEntry("custom");
    if (entry != null)
    {
      String[] tokens = entry.getTokens();
      if ((tokens.length == 1) && (tokens[0].equalsIgnoreCase("true"))) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.builders.BuildErrorReporter
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.builders;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.osgi.service.resolver.ResolverError;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateHelper;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.core.plugin.IFragmentModel;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.AbstractNLModel;
import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.NLResourceHelper;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.PDECoreMessages;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
import org.eclipse.pde.internal.core.project.PDEProject;
import org.eclipse.pde.internal.core.search.PluginJavaSearchUtil;
import org.eclipse.pde.internal.core.util.IdUtil;
import org.eclipse.pde.internal.core.util.ManifestUtils;
import org.eclipse.pde.internal.core.util.PDEJavaHelper;
import org.eclipse.pde.internal.core.util.VersionUtil;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;

public class BundleErrorReporter
  extends JarManifestErrorReporter
{
  private boolean fOsgiR4;
  private IPluginModelBase fModel;
  private Set fProjectPackages;
  
  public BundleErrorReporter(IFile file)
  {
    super(file);
  }
  
  public void validateContent(IProgressMonitor monitor)
  {
    super.validateContent(monitor);
    if ((fHeaders == null) || (getErrorCount() > 0)) {
      return;
    }
    fModel = PluginRegistry.findModel(fProject);
    if ((fModel == null) || (!validateBundleSymbolicName())) {
      return;
    }
    validateFragmentHost();
    validateBundleVersion();
    validateRequiredExecutionEnvironment();
    
    validateEclipsePlatformFilter();
    validateBundleActivator();
    validateBundleClasspath();
    validateRequireBundle(monitor);
    validateImportPackage(monitor);
    validateExportPackage(monitor);
    validateExportPackages();
    validateAutoStart();
    validateLazyStart();
    validateBundleActivatorPolicy();
    validateExtensibleAPI();
    validateTranslatableHeaders();
    validateImportExportServices();
    validateBundleLocalization();
    validateProvidePackage();
    validateEclipseBundleShape();
  }
  
  private boolean validateBundleManifestVersion()
  {
    IHeader header = getHeader("Bundle-ManifestVersion");
    if (header != null)
    {
      String version = header.getValue();
      if ((!(fOsgiR4 = "2".equals(version))) && (!"1".equals(version)))
      {
        report(PDECoreMessages.BundleErrorReporter_illegalManifestVersion, header.getLineNumber() + 1, 0, "fatal");
        return false;
      }
    }
    return true;
  }
  
  private void validateExportPackages()
  {
    IHeader header = getHeader("Export-Package");
    if ((fModel instanceof IBundlePluginModelBase))
    {
      IBundlePluginModelBase bundleModel = (IBundlePluginModelBase)fModel;
      IBundle bundle = bundleModel.getBundleModel().getBundle();
      IManifestHeader bundleClasspathheader = bundle.getManifestHeader("Bundle-ClassPath");
      
      IPackageFragmentRoot[] roots = ManifestUtils.findPackageFragmentRoots(bundleClasspathheader, fProject);
      
      StringBuffer packages = new StringBuffer();
      for (int i = 0; i < roots.length; i++) {
        try
        {
          if (ManifestUtils.isImmediateRoot(roots[i]))
          {
            IJavaElement[] javaElements = roots[i].getChildren();
            for (int j = 0; j < javaElements.length; j++) {
              if ((javaElements[j] instanceof IPackageFragment))
              {
                IPackageFragment fragment = (IPackageFragment)javaElements[j];
                String name = fragment.getElementName();
                if (name.length() == 0) {
                  name = ".";
                }
                if (((fragment.containsJavaResources()) || (fragment.getNonJavaResources().length > 0)) && 
                  (!containsPackage(header, name)))
                {
                  packages.append(name);
                  if (j < javaElements.length - 1) {
                    packages.append(",");
                  }
                }
              }
            }
          }
        }
        catch (JavaModelException localJavaModelException) {}
      }
      if (packages.toString().length() > 0)
      {
        IMarker marker = report(PDECoreMessages.BundleErrorReporter_missingPackagesInProject, header == null ? 1 : header.getLineNumber() + 1, "compilers.p.missing-packages", 4120, "");
        addMarkerAttribute(marker, "packages", packages.toString());
      }
    }
  }
  
  private boolean validateBundleSymbolicName()
  {
    IHeader header = validateRequiredHeader("Bundle-SymbolicName");
    if (
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd