Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.rpm;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you 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.
  */
 
 import java.io.File;
 import java.io.Reader;

Defines a scriptlet including the optinal getSubpackage() and getProgram(). The (optional) contents can be provided by either getScript() or getScriptFile().

Author(s):
Brett Okken, Cerner Corp.
Since:
2.0-beta-4
 
 public class Scriptlet
 {
    
Optional subpackage.

See also:
getSubpackage()
 
     private String subpackage;

    
Program to execute script.

See also:
getProgram()
 
     private String program;

    
Contents of the script. Mutually exclusive with scriptFile.

See also:
getScript()
 
     private String script;

    
Script to execute. Mutually exclusive with script.

See also:
getScriptFile()
 
     private File scriptFile;

    
Encoding of scriptFile.

See also:
getFileEncoding().
 
     private String fileEncoding;

    
The default encoding of the project, used if fileEncoding is not set.

See also:
getFileEncoding().
 
     private String sourceEncoding;

    
The optional subpackage. This is passed as a -n argument to the scriptlet directive.

Returns:
Returns the subpackage.
 
     public String getSubpackage()
     {
         return this.;
     }

    

Parameters:
subpackage The subpackage to set.
 
     public void setSubpackageString subpackage )
     {
         this. = subpackage;
     }

    
The program to use to execute the script. This is passed as a -p argument to the scriptlet directive.

Returns:
Returns the program.
    public String getProgram()
    {
        return this.;
    }

    

Parameters:
program The program to set.
    public void setProgramString program )
    {
        this. = program;
    }

    
The contents of the script as a String. This value will override anything at getScriptFile().

Returns:
Returns the script.
    public String getScript()
    {
        return this.;
    }

    

Parameters:
script The script to set.
    public void setScriptString script )
    {
        this. = script;
    }

    
The contents of the script as a File. This will be ignored if getScript() is populated.

Returns:
Returns the scriptFile.
    public File getScriptFile()
    {
        return this.;
    }

    

Parameters:
scriptFile The scriptFile to set.
    public void setScriptFileFile scriptFile )
    {
        this. = scriptFile;
    }

    
The encoding to use to read getScriptFile(). If null, the default character encoding for th platform will be used.

Returns:
Returns the fileEncoding.
    public String getFileEncoding()
    {
        if (  != null && !"".equals ) )
        {
            return this.;
        }
        return this.;
    }

    

Parameters:
fileEncoding The fileEncoding to set.
    public void setFileEncodingString fileEncoding )
    {
        this. = fileEncoding;
    }

    
This is the maven property: project.build.sourceEncoding

Parameters:
soruceEncoding The sourceEncoding to set.
    public void setSourceEncodingString sourceEncoding )
    {
        this. = sourceEncoding;
    }

    
Writes the scriptlet.

Parameters:
writer PrintWriter to write content to.
directive The directive for the scriptlet.
Throws:
java.io.IOException
    protected final void writefinal PrintWriter writerfinal String directive )
        throws IOException
    {
        if (  != null && !.exists() )
        {
            throw new RuntimeException"Invalid scriptlet declaration found - defined scriptFile does not exist: "
                + .getPath() );
        }
        if (  != null || (  != null && .exists() ) ||  != null )
        {
            writer.println();
            writer.printlnbuildScriptletLinedirective ) );
            writeContentwriter );
        }
    }

    
Builds the scriptlet line including any optional args.

Parameters:
directive The directive for the scriptlet.
Returns:
The scriptlet line - this does not include the script.
    protected String buildScriptletLinefinal String directive )
    {
        final StringBuilder builder = new StringBuilder();
        builder.appenddirective );
        if (  != null )
        {
            builder.append" -n " );
            builder.append );
        }
        if (  != null )
        {
            builder.append" -p " );
            builder.append );
        }
        return builder.toString();
    }

    
Writes the content (either getScript() or getScriptFile()) to writer.

Parameters:
writer PrintWriter to write content to.
Throws:
java.io.IOException
    protected final void writeContentPrintWriter writer )
        throws IOException
    {
        if (  != null )
        {
            writer.println );
        }
        else if ( .exists() )
        {
            final Reader reader =
                 != null ? new InputStreamReadernew FileInputStream ),  )
                                : new FileReader );
            BufferedReader bufferedReader = null;
            try
            {
                bufferedReader = new BufferedReaderreader );
                String line;
                while ( ( line = bufferedReader.readLine() ) != null )
                {
                    writer.printlnline );
                }
            }
            finally
            {
                if ( bufferedReader != null )
                {
                    try
                    {
                        bufferedReader.close();
                    }
                    catch ( IOException e )
                    {
                        // ignore - it does not matter
                    }
                }
                try
                {
                    reader.close();
                }
                catch ( IOException e )
                {
                    // ignore - it does not matter
                }
            }
        }
    }

    
    public String toString()
    {
        StringBuilder buffer = new StringBuilder( 64 );
        buffer.append"Scriptlet[" );
        buffer.append"subpackage=" );
        buffer.append );
        buffer.append",program=" );
        buffer.append );
        buffer.append",script=" );
        buffer.append );
        buffer.append",scriptFile=" );
        buffer.append );
        buffer.append",fileEncoding=" );
        buffer.append );
        buffer.append"]" );
        return buffer.toString();
    }
New to GrepCode? Check out our FAQ X