All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.code.sbt.compiler.api.Compilers Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright 2013-2016 Grzegorz Slowikowski (gslowikowski at gmail dot com)
 *
 * 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 com.google.code.sbt.compiler.api;

import java.io.File;

/**
 * Helper class.
 * 
 * @author Grzegorz Slowikowski
 */
public class Compilers
{
    private static final String CLASSES = "classes";
    
    private static final String TEST_CLASSES = "test-classes";
    
    private static final String CACHE = "cache";
    
    private Compilers()
    {
    }

    /**
     * Returns compiler ID compatible with given SBT or Play! Framework version. 
     * 
     * @param sbtVersion SBT version
     * @param playVersion Play! Framework version
     * 
     * @return compiler ID
     */
    public static String getDefaultCompilerId( String sbtVersion, String playVersion )
    {
        String result = null;
        if ( sbtVersion != null && !sbtVersion.isEmpty() )
        {
            if ( sbtVersion.equals( "0.13" ) || sbtVersion.startsWith( "0.13." ) )
            {
                result = "sbt013";
            }
            else if ( sbtVersion.equals( "0.12" ) || sbtVersion.startsWith( "0.12." ) )
            {
                result = "sbt012";
            }
        }
        if ( result == null )
        {
            if ( playVersion != null && !playVersion.isEmpty() )
            {
                if ( playVersion.startsWith( "2.1." ) || playVersion.startsWith( "2.1-" ) )
                {
                    result = "sbt012";
                }
            }
        }
        if ( result == null )
        {
            result = "sbt013"; // use latest version
        }
        return result;
    }

    /**
     * Returns directory for incremental compilation cache files.
     * 
     * @param classesDirectory compilation output directory 
     * @return directory for incremental compilation cache files
     */
    public static File getCacheDirectory( File classesDirectory )
    {
        String classesDirectoryName = classesDirectory.getName();
        String cacheDirectoryName = classesDirectoryName.replace( TEST_CLASSES, CACHE ).replace( CLASSES, CACHE );
        return new File( classesDirectory.getParentFile(), cacheDirectoryName );
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy