Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.codehaus.gmavenplus.groovyworkarounds;
 
 
 import java.io.File;
 import java.net.URI;
 import java.util.Set;


This class exists solely to trick JavaStubCompilationUnit.addSource(java.io.File) into letting us use files that don't end in ".groovy" (as a workaround for GROOVY-5021).

Author(s):
Keegan Witt
Since:
1.0-beta-1
 
 public class DotGroovyFile extends File {

    
The file extensions to consider as Groovy files.
 
     private Set<StringscriptExtensions = new HashSet<String>();

    
Constructs a new DotGroovyFile object with the specified parameters.

Parameters:
pathname Pathname to use to create DotGroovyFile
 
     public DotGroovyFile(final String pathname) {
         super(pathname);
     }

    
Constructs a new DotGroovyFile object with the specified parameters.

Parameters:
parent Parent pathname to use to create DotGroovyFile
child Child pathname to use to create DotGroovyFile
 
     public DotGroovyFile(final String parentfinal String child) {
         super(parentchild);
     }

    
Constructs a new DotGroovyFile object with the specified parameters.

Parameters:
parent Parent file to use to create DotGroovyFile
child Child pathname to use to create DotGroovyFile
 
     public DotGroovyFile(final File parentfinal String child) {
         super(parentchild);
     }

    
Constructs a new DotGroovyFile object with the specified parameters.

Parameters:
uri URI to use to create DotGroovyFile
 
     public DotGroovyFile(final URI uri) {
         super(uri);
     }

    
A convenience constructor to turn a regular file into a DotGroovyFile.

Parameters:
file File to use to create DotGroovyFile
 
     public DotGroovyFile(final File file) {
         super(file.getAbsolutePath());
     }

    
Default Groovy file extensions (currently '.groovy', '.gvy', '.gy', and '.gsh').

Returns:
The default Groovy file extensions
 
     public static Set<StringdefaultScriptExtensions() {
         Set<StringdefaultScriptExtensions = new HashSet<String>();
 
         defaultScriptExtensions.add("groovy");
         defaultScriptExtensions.add("gvy");
         defaultScriptExtensions.add("gy");
        defaultScriptExtensions.add("gsh");
        return defaultScriptExtensions;
    }

    
A method to lie about the file extension and say it is ".groovy".

Returns:
Filename with forced .groovy extension
    public String getName() {
        if ( != null && !.isEmpty() && .contains(FileUtils.getFileExtension(super.getAbsolutePath()))) {
            return FileUtils.getNameWithoutExtension(super.getName()) + ".groovy";
        } else {
            return super.getName();
        }
    }

    
Gets the script extensions for this Groovy file.

Returns:
The script extensions for this Groovy file
    public Set<StringgetScriptExtensions() {
        return ;
    }

    
Sets the script extensions for this Groovy file.

Parameters:
newScriptExtensions The script extensions to set on this Groovy file
Returns:
This object (for fluent invocation)
    public DotGroovyFile setScriptExtensions(final Set<StringnewScriptExtensions) {
         = newScriptExtensions;
        return this;
    }
New to GrepCode? Check out our FAQ X