Add support for .nbignore files
authorTomas Mysik <tmysik@netbeans.org>
Thu, 04 Aug 2016 10:10:11 +0200
changeset 18368bf3816d2231a
parent 18367 b5d1baefdde0
child 18369 a80c195141c6
Add support for .nbignore files
nbignore/build.xml
nbignore/manifest.mf
nbignore/nbproject/project.properties
nbignore/nbproject/project.xml
nbignore/src/org/netbeans/modules/nbignore/NbIgnoreVisibilityQueryImpl.java
nbignore/src/org/netbeans/modules/nbignore/resources/Bundle.properties
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nbignore/build.xml	Thu Aug 04 10:10:11 2016 +0200
     1.3 @@ -0,0 +1,44 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<!--
     1.6 +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.7 +
     1.8 +Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
     1.9 +
    1.10 +Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    1.11 +Other names may be trademarks of their respective owners.
    1.12 +
    1.13 +The contents of this file are subject to the terms of either the GNU
    1.14 +General Public License Version 2 only ("GPL") or the Common
    1.15 +Development and Distribution License("CDDL") (collectively, the
    1.16 +"License"). You may not use this file except in compliance with the
    1.17 +License. You can obtain a copy of the License at
    1.18 +http://www.netbeans.org/cddl-gplv2.html
    1.19 +or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.20 +specific language governing permissions and limitations under the
    1.21 +License.  When distributing the software, include this License Header
    1.22 +Notice in each file and include the License file at
    1.23 +nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    1.24 +particular file as subject to the "Classpath" exception as provided
    1.25 +by Oracle in the GPL Version 2 section of the License file that
    1.26 +accompanied this code. If applicable, add the following below the
    1.27 +License Header, with the fields enclosed by brackets [] replaced by
    1.28 +your own identifying information:
    1.29 +"Portions Copyrighted [year] [name of copyright owner]"
    1.30 +
    1.31 +If you wish your version of this file to be governed by only the CDDL
    1.32 +or only the GPL Version 2, indicate your decision by adding
    1.33 +"[Contributor] elects to include this software in this distribution
    1.34 +under the [CDDL or GPL Version 2] license." If you do not indicate a
    1.35 +single choice of license, a recipient has the option to distribute
    1.36 +your version of this file under either the CDDL, the GPL Version 2 or
    1.37 +to extend the choice of license to its licensees as provided above.
    1.38 +However, if you add GPL Version 2 code and therefore, elected the GPL
    1.39 +Version 2 license, then the option applies only if the new code is
    1.40 +made subject to such option by the copyright holder.
    1.41 +
    1.42 +Contributor(s):
    1.43 +-->
    1.44 +<project basedir="." default="netbeans" name="contrib/nbignore">
    1.45 +    <description>Builds, tests, and runs the project org.netbeans.modules.nbignore</description>
    1.46 +    <import file="../../nbbuild/templates/projectized.xml"/>
    1.47 +</project>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/nbignore/manifest.mf	Thu Aug 04 10:10:11 2016 +0200
     2.3 @@ -0,0 +1,6 @@
     2.4 +Manifest-Version: 1.0
     2.5 +AutoUpdate-Show-In-Client: true
     2.6 +OpenIDE-Module: org.netbeans.modules.nbignore
     2.7 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/nbignore/resources/Bundle.properties
     2.8 +OpenIDE-Module-Specification-Version: 0.1
     2.9 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/nbignore/nbproject/project.properties	Thu Aug 04 10:10:11 2016 +0200
     3.3 @@ -0,0 +1,4 @@
     3.4 +javac.source=1.8
     3.5 +javac.compilerargs=-Xlint -Xlint:-serial
     3.6 +nbm.homepage=https://netbeans.org/
     3.7 +nbm.module.author=Tomas Mysik, Jaroslav Havlin
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/nbignore/nbproject/project.xml	Thu Aug 04 10:10:11 2016 +0200
     4.3 @@ -0,0 +1,84 @@
     4.4 +<?xml version="1.0" encoding="UTF-8"?>
     4.5 +<!--
     4.6 +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     4.7 +
     4.8 +Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
     4.9 +
    4.10 +Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    4.11 +Other names may be trademarks of their respective owners.
    4.12 +
    4.13 +The contents of this file are subject to the terms of either the GNU
    4.14 +General Public License Version 2 only ("GPL") or the Common
    4.15 +Development and Distribution License("CDDL") (collectively, the
    4.16 +"License"). You may not use this file except in compliance with the
    4.17 +License. You can obtain a copy of the License at
    4.18 +http://www.netbeans.org/cddl-gplv2.html
    4.19 +or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    4.20 +specific language governing permissions and limitations under the
    4.21 +License.  When distributing the software, include this License Header
    4.22 +Notice in each file and include the License file at
    4.23 +nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    4.24 +particular file as subject to the "Classpath" exception as provided
    4.25 +by Oracle in the GPL Version 2 section of the License file that
    4.26 +accompanied this code. If applicable, add the following below the
    4.27 +License Header, with the fields enclosed by brackets [] replaced by
    4.28 +your own identifying information:
    4.29 +"Portions Copyrighted [year] [name of copyright owner]"
    4.30 +
    4.31 +If you wish your version of this file to be governed by only the CDDL
    4.32 +or only the GPL Version 2, indicate your decision by adding
    4.33 +"[Contributor] elects to include this software in this distribution
    4.34 +under the [CDDL or GPL Version 2] license." If you do not indicate a
    4.35 +single choice of license, a recipient has the option to distribute
    4.36 +your version of this file under either the CDDL, the GPL Version 2 or
    4.37 +to extend the choice of license to its licensees as provided above.
    4.38 +However, if you add GPL Version 2 code and therefore, elected the GPL
    4.39 +Version 2 license, then the option applies only if the new code is
    4.40 +made subject to such option by the copyright holder.
    4.41 +
    4.42 +Contributor(s):
    4.43 +-->
    4.44 +<project xmlns="http://www.netbeans.org/ns/project/1">
    4.45 +    <type>org.netbeans.modules.apisupport.project</type>
    4.46 +    <configuration>
    4.47 +        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
    4.48 +            <code-name-base>org.netbeans.modules.nbignore</code-name-base>
    4.49 +            <module-dependencies>
    4.50 +                <dependency>
    4.51 +                    <code-name-base>org.netbeans.modules.queries</code-name-base>
    4.52 +                    <build-prerequisite/>
    4.53 +                    <compile-dependency/>
    4.54 +                    <run-dependency>
    4.55 +                        <release-version>1</release-version>
    4.56 +                        <specification-version>1.43</specification-version>
    4.57 +                    </run-dependency>
    4.58 +                </dependency>
    4.59 +                <dependency>
    4.60 +                    <code-name-base>org.openide.filesystems</code-name-base>
    4.61 +                    <build-prerequisite/>
    4.62 +                    <compile-dependency/>
    4.63 +                    <run-dependency>
    4.64 +                        <specification-version>9.10</specification-version>
    4.65 +                    </run-dependency>
    4.66 +                </dependency>
    4.67 +                <dependency>
    4.68 +                    <code-name-base>org.openide.util</code-name-base>
    4.69 +                    <build-prerequisite/>
    4.70 +                    <compile-dependency/>
    4.71 +                    <run-dependency>
    4.72 +                        <specification-version>9.7</specification-version>
    4.73 +                    </run-dependency>
    4.74 +                </dependency>
    4.75 +                <dependency>
    4.76 +                    <code-name-base>org.openide.util.lookup</code-name-base>
    4.77 +                    <build-prerequisite/>
    4.78 +                    <compile-dependency/>
    4.79 +                    <run-dependency>
    4.80 +                        <specification-version>8.33</specification-version>
    4.81 +                    </run-dependency>
    4.82 +                </dependency>
    4.83 +            </module-dependencies>
    4.84 +            <public-packages/>
    4.85 +        </data>
    4.86 +    </configuration>
    4.87 +</project>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/nbignore/src/org/netbeans/modules/nbignore/NbIgnoreVisibilityQueryImpl.java	Thu Aug 04 10:10:11 2016 +0200
     5.3 @@ -0,0 +1,125 @@
     5.4 +/*
     5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 + *
     5.7 + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
     5.8 + *
     5.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    5.10 + * Other names may be trademarks of their respective owners.
    5.11 + *
    5.12 + * The contents of this file are subject to the terms of either the GNU
    5.13 + * General Public License Version 2 only ("GPL") or the Common
    5.14 + * Development and Distribution License("CDDL") (collectively, the
    5.15 + * "License"). You may not use this file except in compliance with the
    5.16 + * License. You can obtain a copy of the License at
    5.17 + * http://www.netbeans.org/cddl-gplv2.html
    5.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.19 + * specific language governing permissions and limitations under the
    5.20 + * License.  When distributing the software, include this License Header
    5.21 + * Notice in each file and include the License file at
    5.22 + * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    5.23 + * particular file as subject to the "Classpath" exception as provided
    5.24 + * by Oracle in the GPL Version 2 section of the License file that
    5.25 + * accompanied this code. If applicable, add the following below the
    5.26 + * License Header, with the fields enclosed by brackets [] replaced by
    5.27 + * your own identifying information:
    5.28 + * "Portions Copyrighted [year] [name of copyright owner]"
    5.29 + *
    5.30 + * If you wish your version of this file to be governed by only the CDDL
    5.31 + * or only the GPL Version 2, indicate your decision by adding
    5.32 + * "[Contributor] elects to include this software in this distribution
    5.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    5.34 + * single choice of license, a recipient has the option to distribute
    5.35 + * your version of this file under either the CDDL, the GPL Version 2 or
    5.36 + * to extend the choice of license to its licensees as provided above.
    5.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    5.38 + * Version 2 license, then the option applies only if the new code is
    5.39 + * made subject to such option by the copyright holder.
    5.40 + *
    5.41 + * Contributor(s):
    5.42 + */
    5.43 +package org.netbeans.modules.nbignore;
    5.44 +
    5.45 +import java.io.File;
    5.46 +import javax.swing.event.ChangeListener;
    5.47 +import org.netbeans.spi.queries.VisibilityQueryImplementation;
    5.48 +import org.netbeans.spi.queries.VisibilityQueryImplementation2;
    5.49 +import org.openide.filesystems.FileChangeAdapter;
    5.50 +import org.openide.filesystems.FileEvent;
    5.51 +import org.openide.filesystems.FileObject;
    5.52 +import org.openide.filesystems.FileUtil;
    5.53 +import org.openide.util.ChangeSupport;
    5.54 +import org.openide.util.lookup.ServiceProvider;
    5.55 +import org.openide.util.lookup.ServiceProviders;
    5.56 +
    5.57 +/**
    5.58 + * Ignore (hide) folders that contain .nbignore file.
    5.59 + */
    5.60 +@ServiceProviders({
    5.61 +    @ServiceProvider(service = VisibilityQueryImplementation2.class, position = 8765),
    5.62 +    @ServiceProvider(service = VisibilityQueryImplementation.class, position = 8765)
    5.63 +})
    5.64 +public class NbIgnoreVisibilityQueryImpl implements VisibilityQueryImplementation2 {
    5.65 +
    5.66 +    private static final String FILE_NAME = ".nbignore"; // NOI18N
    5.67 +
    5.68 +    private final ChangeSupport changeSupport = new ChangeSupport(this);
    5.69 +
    5.70 +
    5.71 +    public NbIgnoreVisibilityQueryImpl() {
    5.72 +        FileUtil.addFileChangeListener(new FsListener(changeSupport));
    5.73 +    }
    5.74 +
    5.75 +    @Override
    5.76 +    public boolean isVisible(File file) {
    5.77 +        return !(new File(file, FILE_NAME).exists());
    5.78 +    }
    5.79 +
    5.80 +    @Override
    5.81 +    public boolean isVisible(FileObject file) {
    5.82 +        if (file.isFolder()) {
    5.83 +            return file.getFileObject(FILE_NAME) == null;
    5.84 +        }
    5.85 +        return true;
    5.86 +    }
    5.87 +
    5.88 +    @Override
    5.89 +    public void addChangeListener(ChangeListener listener) {
    5.90 +        changeSupport.addChangeListener(listener);
    5.91 +    }
    5.92 +
    5.93 +    @Override
    5.94 +    public void removeChangeListener(ChangeListener listener) {
    5.95 +        changeSupport.removeChangeListener(listener);
    5.96 +    }
    5.97 +
    5.98 +    //~ Inner classes
    5.99 +
   5.100 +    private static final class FsListener extends FileChangeAdapter {
   5.101 +
   5.102 +        private final ChangeSupport changeSupport;
   5.103 +
   5.104 +
   5.105 +        FsListener(ChangeSupport changeSupport) {
   5.106 +            assert changeSupport != null;
   5.107 +            this.changeSupport = changeSupport;
   5.108 +        }
   5.109 +
   5.110 +        @Override
   5.111 +        public void fileDataCreated(FileEvent fe) {
   5.112 +            checkNewOrDeletedFile(fe);
   5.113 +        }
   5.114 +
   5.115 +        @Override
   5.116 +        public void fileDeleted(FileEvent fe) {
   5.117 +            checkNewOrDeletedFile(fe);
   5.118 +        }
   5.119 +
   5.120 +        private void checkNewOrDeletedFile(FileEvent fe) {
   5.121 +            if (fe.getFile().getNameExt().equals(FILE_NAME)) {
   5.122 +                changeSupport.fireChange();
   5.123 +            }
   5.124 +        }
   5.125 +
   5.126 +    }
   5.127 +
   5.128 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/nbignore/src/org/netbeans/modules/nbignore/resources/Bundle.properties	Thu Aug 04 10:10:11 2016 +0200
     6.3 @@ -0,0 +1,39 @@
     6.4 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     6.5 +#
     6.6 +# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
     6.7 +#
     6.8 +# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
     6.9 +# Other names may be trademarks of their respective owners.
    6.10 +#
    6.11 +# The contents of this file are subject to the terms of either the GNU
    6.12 +# General Public License Version 2 only ("GPL") or the Common
    6.13 +# Development and Distribution License("CDDL") (collectively, the
    6.14 +# "License"). You may not use this file except in compliance with the
    6.15 +# License. You can obtain a copy of the License at
    6.16 +# http://www.netbeans.org/cddl-gplv2.html
    6.17 +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    6.18 +# specific language governing permissions and limitations under the
    6.19 +# License.  When distributing the software, include this License Header
    6.20 +# Notice in each file and include the License file at
    6.21 +# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    6.22 +# particular file as subject to the "Classpath" exception as provided
    6.23 +# by Oracle in the GPL Version 2 section of the License file that
    6.24 +# accompanied this code. If applicable, add the following below the
    6.25 +# License Header, with the fields enclosed by brackets [] replaced by
    6.26 +# your own identifying information:
    6.27 +# "Portions Copyrighted [year] [name of copyright owner]"
    6.28 +#
    6.29 +# If you wish your version of this file to be governed by only the CDDL
    6.30 +# or only the GPL Version 2, indicate your decision by adding
    6.31 +# "[Contributor] elects to include this software in this distribution
    6.32 +# under the [CDDL or GPL Version 2] license." If you do not indicate a
    6.33 +# single choice of license, a recipient has the option to distribute
    6.34 +# your version of this file under either the CDDL, the GPL Version 2 or
    6.35 +# to extend the choice of license to its licensees as provided above.
    6.36 +# However, if you add GPL Version 2 code and therefore, elected the GPL
    6.37 +# Version 2 license, then the option applies only if the new code is
    6.38 +# made subject to such option by the copyright holder.
    6.39 +#
    6.40 +# Contributor(s):
    6.41 +
    6.42 +OpenIDE-Module-Name=Support for .nbignore files