Example usage for org.eclipse.jdt.core JavaCore CORE_JAVA_BUILD_DUPLICATE_RESOURCE

List of usage examples for org.eclipse.jdt.core JavaCore CORE_JAVA_BUILD_DUPLICATE_RESOURCE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore CORE_JAVA_BUILD_DUPLICATE_RESOURCE.

Prototype

String CORE_JAVA_BUILD_DUPLICATE_RESOURCE

To view the source code for org.eclipse.jdt.core JavaCore CORE_JAVA_BUILD_DUPLICATE_RESOURCE.

Click Source Link

Document

Core option ID: Reporting Duplicate Resources.

Usage

From source file:net.sf.j2s.core.builder.BatchImageBuilder.java

License:Open Source License

protected void copyExtraResourcesBack(ClasspathMultiDirectory sourceLocation, final boolean deletedAll)
        throws CoreException {
    // When, if ever, does a builder need to copy resources files (not .java or .class) into the output folder?
    // If we wipe the output folder at the beginning of the build then all 'extra' resources must be copied to the output folder.

    this.notifier.subTask(Messages.build_copyingResources);
    final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
    final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
    final char[][] inclusionPatterns = sourceLocation.inclusionPatterns;
    final IContainer outputFolder = sourceLocation.binaryFolder;
    final boolean isAlsoProject = sourceLocation.sourceFolder.equals(this.javaBuilder.currentProject);
    sourceLocation.sourceFolder.accept(new IResourceProxyVisitor() {
        public boolean visit(IResourceProxy proxy) throws CoreException {
            IResource resource = null;/*w  w  w  .  j av a 2  s  .  co m*/
            switch (proxy.getType()) {
            case IResource.FILE:
                if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName())
                        || org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName()))
                    return false;

                resource = proxy.requestResource();
                if (BatchImageBuilder.this.javaBuilder.filterExtraResource(resource))
                    return false;
                if (exclusionPatterns != null || inclusionPatterns != null)
                    if (Util.isExcluded(resource.getFullPath(), inclusionPatterns, exclusionPatterns, false))
                        return false;

                IPath partialPath = resource.getFullPath().removeFirstSegments(segmentCount);
                IResource copiedResource = outputFolder.getFile(partialPath);
                if (copiedResource.exists()) {
                    if (deletedAll) {
                        IResource originalResource = findOriginalResource(partialPath);
                        String id = originalResource.getFullPath().removeFirstSegments(1).toString();
                        createProblemFor(resource, null, Messages.bind(Messages.build_duplicateResource, id),
                                BatchImageBuilder.this.javaBuilder.javaProject
                                        .getOption(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE, true));
                        return false;
                    }
                    copiedResource.delete(IResource.FORCE, null); // last one wins
                }
                createFolder(partialPath.removeLastSegments(1), outputFolder); // ensure package folder exists
                copyResource(resource, copiedResource);
                return false;
            case IResource.FOLDER:
                resource = proxy.requestResource();
                if (BatchImageBuilder.this.javaBuilder.filterExtraResource(resource))
                    return false;
                if (isAlsoProject && isExcludedFromProject(resource.getFullPath()))
                    return false; // the sourceFolder == project
                if (exclusionPatterns != null && inclusionPatterns == null) // must walk children if inclusionPatterns != null
                    if (Util.isExcluded(resource.getFullPath(), null, exclusionPatterns, true))
                        return false;
            }
            return true;
        }
    }, IResource.NONE);
}

From source file:org.eclipse.ajdt.core.builder.AJBuilder.java

License:Open Source License

/**
 * Bug 91131 - Checking to see if the user has selected to use project 
 * setting for building. Unfortunately, there is no way of checking 
 * whether the user has selected to use project settings other than to 
 * see whether the options contained on the building page are in the
 * IEclipsePreferences. There is also the need for this extra check,
 * rather than just whether there are any IEclipsePreferences, 
 * in Eclipse 3.1 because there are several property pages for the 
 * different compiler options.//  w  w w  .java 2 s. c  o m
 */
private boolean usingProjectBuildingOptions(String[] keys) {
    List<String> listOfKeys = Arrays.asList(keys);
    return (listOfKeys.contains(JavaCore.COMPILER_PB_MAX_PER_UNIT)
            || listOfKeys.contains(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE)
            || listOfKeys.contains(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH)
            || listOfKeys.contains(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER)
            || listOfKeys.contains(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS)
            || listOfKeys.contains(JavaCore.CORE_CIRCULAR_CLASSPATH)
            || listOfKeys.contains(JavaCore.CORE_INCOMPLETE_CLASSPATH)
            || listOfKeys.contains(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL));
}

From source file:org.eclipse.jdt.internal.core.builder.BatchImageBuilder.java

License:Open Source License

protected void copyExtraResourcesBack(ClasspathMultiDirectory sourceLocation, final boolean deletedAll)
        throws CoreException {
    // When, if ever, does a builder need to copy resources files (not .java or .class) into the output folder?
    // If we wipe the output folder at the beginning of the build then all 'extra' resources must be copied to the output folder.

    this.notifier.subTask(Messages.build_copyingResources);
    final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
    final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
    final char[][] inclusionPatterns = sourceLocation.inclusionPatterns;
    final IContainer outputFolder = sourceLocation.binaryFolder;
    final boolean isAlsoProject = sourceLocation.sourceFolder.equals(this.javaBuilder.currentProject);
    // GROOVY start
    final boolean isInterestingProject = LanguageSupportFactory
            .isInterestingProject(this.javaBuilder.getProject());
    // GROOVY end
    sourceLocation.sourceFolder.accept(new IResourceProxyVisitor() {
        public boolean visit(IResourceProxy proxy) throws CoreException {
            IResource resource = null;/*from  w  ww . j a  v  a  2s.  c om*/
            switch (proxy.getType()) {
            case IResource.FILE:
                // GROOVY start
                /* old {
                if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName()) ||
                   org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) return false;
                } new */
                // copy groovy files if not in a groovy project
                // Also, must keep the call to 'isJavaLikeFileName' to keep Scala plugin happy: GRECLIPSE-404
                // here it is the same test as above, except 
                if ((LanguageSupportFactory.isSourceFile(proxy.getName(), isInterestingProject)
                        && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(proxy.getName()))
                        || org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName()))
                    return false;
                // GROOVY end

                resource = proxy.requestResource();
                if (BatchImageBuilder.this.javaBuilder.filterExtraResource(resource))
                    return false;
                if (exclusionPatterns != null || inclusionPatterns != null)
                    if (Util.isExcluded(resource.getFullPath(), inclusionPatterns, exclusionPatterns, false))
                        return false;

                IPath partialPath = resource.getFullPath().removeFirstSegments(segmentCount);
                IResource copiedResource = outputFolder.getFile(partialPath);
                if (copiedResource.exists()) {
                    if (deletedAll) {
                        IResource originalResource = findOriginalResource(partialPath);
                        String id = originalResource.getFullPath().removeFirstSegments(1).toString();
                        createProblemFor(resource, null, Messages.bind(Messages.build_duplicateResource, id),
                                BatchImageBuilder.this.javaBuilder.javaProject
                                        .getOption(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE, true));
                        return false;
                    }
                    copiedResource.delete(IResource.FORCE, null); // last one wins
                }
                createFolder(partialPath.removeLastSegments(1), outputFolder); // ensure package folder exists
                copyResource(resource, copiedResource);
                return false;
            case IResource.FOLDER:
                resource = proxy.requestResource();
                if (BatchImageBuilder.this.javaBuilder.filterExtraResource(resource))
                    return false;
                if (isAlsoProject && isExcludedFromProject(resource.getFullPath()))
                    return false; // the sourceFolder == project
                if (exclusionPatterns != null && inclusionPatterns == null) // must walk children if inclusionPatterns != null
                    if (Util.isExcluded(resource.getFullPath(), null, exclusionPatterns, true))
                        return false;
            }
            return true;
        }
    }, IResource.NONE);
}

From source file:org.eclipse.jdt.internal.core.JavaModelManager.java

License:Open Source License

private Hashtable getDefaultOptionsNoInitialization() {
    Map defaultOptionsMap = new CompilerOptions().getMap(); // compiler defaults

    // Override some compiler defaults
    defaultOptionsMap.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.GENERATE);
    defaultOptionsMap.put(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL, JavaCore.PRESERVE);
    defaultOptionsMap.put(JavaCore.COMPILER_TASK_TAGS, JavaCore.DEFAULT_TASK_TAGS);
    defaultOptionsMap.put(JavaCore.COMPILER_TASK_PRIORITIES, JavaCore.DEFAULT_TASK_PRIORITIES);
    defaultOptionsMap.put(JavaCore.COMPILER_TASK_CASE_SENSITIVE, JavaCore.ENABLED);
    defaultOptionsMap.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
    defaultOptionsMap.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, JavaCore.ERROR);

    // Builder settings
    defaultOptionsMap.put(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ABORT);
    defaultOptionsMap.put(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE, JavaCore.WARNING);
    defaultOptionsMap.put(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, JavaCore.CLEAN);

    // JavaCore settings
    defaultOptionsMap.put(JavaCore.CORE_JAVA_BUILD_ORDER, JavaCore.IGNORE);
    defaultOptionsMap.put(JavaCore.CORE_INCOMPLETE_CLASSPATH, JavaCore.ERROR);
    defaultOptionsMap.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.ERROR);
    defaultOptionsMap.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.IGNORE);
    defaultOptionsMap.put(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.WARNING);
    defaultOptionsMap.put(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, JavaCore.ENABLED);
    defaultOptionsMap.put(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, JavaCore.ENABLED);

    // Formatter settings
    defaultOptionsMap.putAll(DefaultCodeFormatterConstants.getEclipseDefaultSettings());

    // CodeAssist settings
    defaultOptionsMap.put(JavaCore.CODEASSIST_VISIBILITY_CHECK, JavaCore.DISABLED);
    defaultOptionsMap.put(JavaCore.CODEASSIST_DEPRECATION_CHECK, JavaCore.DISABLED);
    defaultOptionsMap.put(JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, JavaCore.DISABLED);
    defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_PREFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_PREFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_PREFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_STATIC_FINAL_FIELD_SUFFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_LOCAL_SUFFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_ARGUMENT_SUFFIXES, ""); //$NON-NLS-1$
    defaultOptionsMap.put(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, JavaCore.ENABLED);
    defaultOptionsMap.put(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK, JavaCore.DISABLED);
    defaultOptionsMap.put(JavaCore.CODEASSIST_CAMEL_CASE_MATCH, JavaCore.ENABLED);
    defaultOptionsMap.put(JavaCore.CODEASSIST_SUGGEST_STATIC_IMPORTS, JavaCore.ENABLED);

    // Time out for parameter names
    defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$

    return new Hashtable(defaultOptionsMap);
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Returns the project custom preference pool.
 * Project preferences may include custom encoding.
 * @return IEclipsePreferences or <code>null</code> if the project
 *    does not have a java nature./*ww w . jav a 2 s . c  o  m*/
 */
public IEclipsePreferences getEclipsePreferences() {
    if (!JavaProject.hasJavaNature(this.project))
        return null;
    // Get cached preferences if exist
    JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager()
            .getPerProjectInfo(this.project, true);
    if (perProjectInfo.preferences != null)
        return perProjectInfo.preferences;
    // Init project preferences
    IScopeContext context = new ProjectScope(getProject());
    final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
    updatePreferences(eclipsePreferences);
    perProjectInfo.preferences = eclipsePreferences;

    // Listen to new preferences node
    final IEclipsePreferences eclipseParentPreferences = (IEclipsePreferences) eclipsePreferences.parent();
    if (eclipseParentPreferences != null) {
        if (this.preferencesNodeListener != null) {
            eclipseParentPreferences.removeNodeChangeListener(this.preferencesNodeListener);
        }
        this.preferencesNodeListener = new IEclipsePreferences.INodeChangeListener() {
            public void added(IEclipsePreferences.NodeChangeEvent event) {
                // do nothing
            }

            public void removed(IEclipsePreferences.NodeChangeEvent event) {
                if (event.getChild() == eclipsePreferences) {
                    JavaModelManager.getJavaModelManager().resetProjectPreferences(JavaProject.this);
                }
            }
        };
        eclipseParentPreferences.addNodeChangeListener(this.preferencesNodeListener);
    }

    // Listen to preferences changes
    if (this.preferencesChangeListener != null) {
        eclipsePreferences.removePreferenceChangeListener(this.preferencesChangeListener);
    }
    this.preferencesChangeListener = new IEclipsePreferences.IPreferenceChangeListener() {
        public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
            String propertyName = event.getKey();
            JavaModelManager manager = JavaModelManager.getJavaModelManager();
            if (propertyName.startsWith(JavaCore.PLUGIN_ID)) {
                if (propertyName.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER)
                        || propertyName.equals(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER)
                        || propertyName.equals(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE)
                        || propertyName
                                .equals(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER)
                        || propertyName.equals(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH)
                        || propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS)
                        || propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS)
                        || propertyName.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH)
                        || propertyName.equals(JavaCore.CORE_CIRCULAR_CLASSPATH)
                        || propertyName.equals(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE)
                        || propertyName.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL)) {
                    manager.deltaState.addClasspathValidation(JavaProject.this);
                }
                manager.resetProjectOptions(JavaProject.this);
                JavaProject.this.resetCaches(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568
            }
        }
    };
    eclipsePreferences.addPreferenceChangeListener(this.preferencesChangeListener);
    return eclipsePreferences;
}