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

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

Introduction

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

Prototype

String CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER

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

Click Source Link

Document

Core option ID: Cleaning Output Folder(s).

Usage

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

License:Open Source License

protected void cleanOutputFolders(boolean copyBack) throws CoreException {
    boolean deleteAll = JavaCore.CLEAN
            .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
    if (deleteAll) {
        if (this.javaBuilder.participants != null)
            for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
                this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);

        ArrayList visited = new ArrayList(this.sourceLocations.length);
        for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            this.notifier.subTask(
                    Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
            ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
            if (sourceLocation.hasIndependentOutputFolder) {
                IContainer outputFolder = sourceLocation.binaryFolder;
                if (!visited.contains(outputFolder)) {
                    visited.add(outputFolder);
                    IResource[] members = outputFolder.members();
                    for (int j = 0, m = members.length; j < m; j++) {
                        IResource member = members[j];
                        if (!member.isDerived()) {
                            member.accept(new IResourceVisitor() {
                                public boolean visit(IResource resource) throws CoreException {
                                    resource.setDerived(true, null);
                                    return resource.getType() != IResource.FILE;
                                }/*from w ww .  j  av  a  2s  . co  m*/
                            });
                        }
                        member.delete(IResource.FORCE, null);
                    }
                }
                this.notifier.checkCancel();
                if (copyBack)
                    copyExtraResourcesBack(sourceLocation, true);
            } else {
                boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
                final char[][] exclusionPatterns = isOutputFolder ? sourceLocation.exclusionPatterns : null; // ignore exclusionPatterns if output folder == another source folder... not this one
                final char[][] inclusionPatterns = isOutputFolder ? sourceLocation.inclusionPatterns : null; // ignore inclusionPatterns if output folder == another source folder... not this one
                sourceLocation.binaryFolder.accept(new IResourceProxyVisitor() {
                    public boolean visit(IResourceProxy proxy) throws CoreException {
                        if (proxy.getType() == IResource.FILE) {
                            if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) {
                                IResource resource = proxy.requestResource();
                                if (exclusionPatterns != null || inclusionPatterns != null)
                                    if (Util.isExcluded(resource.getFullPath(), inclusionPatterns,
                                            exclusionPatterns, false))
                                        return false;
                                if (!resource.isDerived())
                                    resource.setDerived(true, null);
                                resource.delete(IResource.FORCE, null);
                            }
                            return false;
                        }
                        if (exclusionPatterns != null && inclusionPatterns == null) // must walk children if inclusionPatterns != null
                            if (Util.isExcluded(proxy.requestFullPath(), null, exclusionPatterns, true))
                                return false;
                        BatchImageBuilder.this.notifier.checkCancel();
                        return true;
                    }
                }, IResource.NONE);
                this.notifier.checkCancel();
            }
            this.notifier.checkCancel();
        }
    } else if (copyBack) {
        for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
            if (sourceLocation.hasIndependentOutputFolder)
                copyExtraResourcesBack(sourceLocation, false);
            this.notifier.checkCancel();
        }
    }
}

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

License:Open Source License

/**
 * Tidies up the output folder before a build. JDT does this by going
 * through the source and deleting the relevant .class files. That works ok
 * if you are also listening to things like resource deletes so that you
 * tidy up some .class files as you go along. AJDT does not do this, so we
 * use a different approach here. We go through the output directory and
 * recursively delete all .class files. This, of course, doesn't cope with
 * resources that might be in the output directory - but I can't delete
 * everything because some people have the output directory set to the top
 * level of their project./*ww  w .j  a v a2  s.c  o  m*/
 * 
 * There is a subtlety with linked folders being used as output folders, but
 * it does work, I added an AJDTUtils helper method which attempts IPath
 * dereferencing. if the IPath is a 'linked folder' then the helper method
 * returns the dereferenced value.
 */
protected void cleanOutputFolders(IJavaProject project, boolean refresh) throws CoreException {
    // Check the project property
    boolean deleteAll = JavaCore.CLEAN
            .equals(project.getOption(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
    if (deleteAll) {
        int numberDeleted = 0;
        IPath[] paths = CoreUtils.getOutputFolders(project);
        for (int i = 0; i < paths.length; i++) {
            numberDeleted += cleanFolder(project, paths[i], refresh);
        }

        // clean inpath out folder
        String inpathOut = AspectJCorePreferences.getProjectInpathOutFolder(project.getProject());
        if (inpathOut != null && !inpathOut.equals("")) { //$NON-NLS-1$
            IPath inpathOutfolder = new Path(inpathOut);
            numberDeleted += cleanFolder(project, inpathOutfolder, refresh);
        }

        AJLog.log(AJLog.BUILDER, "Builder: Tidied output folder(s), removed class files and derived resources"); //$NON-NLS-1$
    }
}

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

License:Open Source License

protected void cleanOutputFolders(boolean copyBack) throws CoreException {
    boolean deleteAll = JavaCore.CLEAN
            .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
    if (deleteAll) {
        if (this.javaBuilder.participants != null)
            for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
                this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);

        ArrayList visited = new ArrayList(this.sourceLocations.length);
        for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            this.notifier.subTask(
                    Messages.bind(Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
            ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
            if (sourceLocation.hasIndependentOutputFolder) {
                IContainer outputFolder = sourceLocation.binaryFolder;
                if (!visited.contains(outputFolder)) {
                    visited.add(outputFolder);
                    IResource[] members = outputFolder.members();
                    for (int j = 0, m = members.length; j < m; j++) {
                        IResource member = members[j];
                        if (!member.isDerived()) {
                            member.accept(new IResourceVisitor() {
                                public boolean visit(IResource resource) throws CoreException {
                                    resource.setDerived(true, null);
                                    return resource.getType() != IResource.FILE;
                                }/*from w  w w .  j ava 2s .  c  o m*/
                            });
                        }
                        member.delete(IResource.FORCE, null);
                    }
                }
                this.notifier.checkCancel();
                if (copyBack)
                    copyExtraResourcesBack(sourceLocation, true);
            } else {
                boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
                final char[][] exclusionPatterns = isOutputFolder ? sourceLocation.exclusionPatterns : null; // ignore exclusionPatterns if output folder == another source folder... not this one
                final char[][] inclusionPatterns = isOutputFolder ? sourceLocation.inclusionPatterns : null; // ignore inclusionPatterns if output folder == another source folder... not this one
                sourceLocation.binaryFolder.accept(new IResourceProxyVisitor() {
                    public boolean visit(IResourceProxy proxy) throws CoreException {
                        if (proxy.getType() == IResource.FILE) {
                            if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(proxy.getName())) {
                                IResource resource = proxy.requestResource();
                                if (exclusionPatterns != null || inclusionPatterns != null)
                                    if (Util.isExcluded(resource.getFullPath(), inclusionPatterns,
                                            exclusionPatterns, false))
                                        return false;
                                if (!resource.isDerived())
                                    resource.setDerived(true, null);
                                resource.delete(IResource.FORCE, null);
                            }
                            return false;
                        }
                        if (exclusionPatterns != null && inclusionPatterns == null) // must walk children if inclusionPatterns != null
                            if (Util.isExcluded(proxy.requestFullPath(), null, exclusionPatterns, true))
                                return false;
                        BatchImageBuilder.this.notifier.checkCancel();
                        return true;
                    }
                }, IResource.NONE);
                this.notifier.checkCancel();
            }
            this.notifier.checkCancel();
        }
    } else if (copyBack) {
        for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
            if (sourceLocation.hasIndependentOutputFolder)
                copyExtraResourcesBack(sourceLocation, false);
            this.notifier.checkCancel();
        }
    }
    // GROOVY start
    LanguageSupportFactory.getEventHandler().handle(this.javaBuilder.javaProject, "cleanOutputFolders");
    // GROOVY end
}

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.j  a va2 s .  co  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;
}