alexo / wro4j

New project location is:https://github.com/wro4j/wro4j
442 stars 110 forks source link

GoogleClosureCompressorProcessor CompilerOptions not settable #224

Open cnsgithub opened 8 years ago

cnsgithub commented 8 years ago

Hi, lets assume i want to set a Compiler option

CompilationLevel cl = CompilationLevel.SIMPLE_OPTIMIZATIONS ; CompilerOptions options = new CompilerOptions(); options.setLanguageIn(LanguageMode.ECMASCRIPT5); cl.setOptionsForCompilationLevel(options);

It doesnt seem to work as the constructor always uses a predefined option set from the pool

optionsPool = new ObjectPoolHelper<CompilerOptions>(new ObjectFactory<CompilerOptions>() { @Override public CompilerOptions create() { return newCompilerOptions(); } });

` final CompilerOptions compilerOptions = optionsPool.getObject();

`

Workaround used now:

` public CustomGoogleClosureCompressorProcessor(final CompilationLevel compilationLevel, final CompilerOptions options) {

     try{
        Validate.notNull(compilationLevel);
        /**
         * Using pool to fix the threadSafety issue. See <a
         * href="http://code.google.com/p/closure-compiler/issues/detail?id=781">issue</a>.
         */
        ObjectPoolHelper<CompilerOptions> optionsPool = new ObjectPoolHelper<CompilerOptions>(new ObjectFactory<CompilerOptions>() {
          @Override
          public CompilerOptions create() {
            return options;
          }
        });

        Field optionsPool_f = this.getClass().getSuperclass().getDeclaredField("optionsPool");
        optionsPool_f.setAccessible(true);
        optionsPool_f.set(this, optionsPool);

        Field compilationLevel_f = this.getClass().getSuperclass().getDeclaredField("compilationLevel");
        compilationLevel_f.setAccessible(true);
        compilationLevel_f.set(this, compilationLevel);
     }catch(Exception e){
         e.printStackTrace();
     }
      }

`

Or am i doing something wrong? Thanks