Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.gwt.shell;
  
  /*
   * 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.util.List;
 
Creates CSS interfaces for css files. Will use the utility tool provided in gwt sdk which create a corresponding Java interface for accessing the classnames used in the file.

Author(s):
Stale Undheim <undheim@corporater.com>
olamy
Since:
2.1.0-1
Goal:
css
 
 public class CSSMojo
     extends AbstractGwtShellMojo
 {
    
List of resourceBundles that should be used to generate CSS interfaces.

Parameter:
 
     private String[] cssFiles;

    
Shortcut for a single cssFile

Parameter:
 
     private String cssFile;
 
     public void doExecute()
     {
         setup();
         boolean generated = false;
 
         // java -cp gwt-dev.jar:gwt-user.jar
         // com.google.gwt.resources.css.InterfaceGenerator -standalone -typeName some.package.MyCssResource -css
         // input.css
         if (  != null )
         {
             for ( String file :  )
             {
                 final String typeName = FilenameUtils.separatorsToSystemfile ).
                     substring( 0, file.lastIndexOf'.' ) ).replace.'.' );
                 final File javaOutput =
                     new FilegetGenerateDirectory(), typeName.replace'.'. ) + ".java" );
                 final StringBuilder content = new StringBuilder();
                  = new StreamConsumer()
                 {
                     public void consumeLineString line )
                     {
                         content.appendline ).append. );
                     }
                 };
                 for ( Resource resource : (List<Resource>) getProject().getResources() )
                 {
                     final File candidate = new Fileresource.getDirectory(), file );
                     if ( candidate.exists() )
                     {
                         getLog().info"Generating " + javaOutput + " with typeName " + typeName );
                         ensureTargetPackageExistsgetGenerateDirectory(), typeName );
 
                         
                         try
                         {
                             new JavaCommand"com.google.gwt.resources.css.InterfaceGenerator" )
                             .withinScope. )
                             .arg"-standalone" )
                            .arg"-typeName" )
                            .argtypeName )
                            .arg"-css" )
                            .argcandidate.getAbsolutePath() )
                            .withinClasspathgetGwtDevJar() )
                            .withinClasspathgetGwtUserJar() )
                            .execute();                            
                            final FileWriter outputWriter = new FileWriterjavaOutput );
                            outputWriter.writecontent.toString() );
                            outputWriter.close();
                        }
                        catch ( IOException e )
                        {
                            throw new MojoExecutionException"Failed to write to file: " + javaOutput );
                        }
                        generated = true;
                        break;
                    }
                }
                
                if ( content.length() == 0 )
                {
                    throw new MojoExecutionException"cannot generate java source from file " + file + "." );
                }
            }
        }
        if ( generated )
        {
            getLog().debug"add compile source root " + getGenerateDirectory() );
            addCompileSourceRootgetGenerateDirectory() );
        }
    }
    private void setup()
        throws MojoExecutionException
    {
        if (  == null &&  != null )
        {
             = new String[] {  };
        }
    }
    private void ensureTargetPackageExistsFile generateDirectoryString targetName )
    {
        targetName = targetName.contains"." ) ? targetName.substring( 0, targetName.lastIndexOf'.' ) ) : targetName;
        String targetPackage = targetName.replace'.'. );
        getLog().debug"ensureTargetPackageExists, targetName : " + targetName + ", targetPackage : " + targetPackage );
        File targetPackageDirectory = new FilegenerateDirectorytargetPackage );
        if ( !targetPackageDirectory.exists() )
        {
            targetPackageDirectory.mkdirs();
        }
    }
New to GrepCode? Check out our FAQ X