<commit_before>/*
 * Copyright 2008 Google Inc.
 *
 * 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.common.css;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.css.JobDescription.InputOrientation;
import com.google.common.css.JobDescription.OptimizeStrategy;
import com.google.common.css.JobDescription.OutputFormat;
import com.google.common.css.JobDescription.OutputOrientation;

import java.util.List;
import java.util.Set;

/**
 * Aids in the creation of inputs for the compiler. A builder can be used for
 * creating a single {@link JobDescription}.
 *
 */
public class JobDescriptionBuilder {
  private List<SourceCode> inputs;
  private String copyrightNotice;
  private OutputFormat outputFormat;
  private InputOrientation inputOrientation;
  private OutputOrientation outputOrientation;
  private OptimizeStrategy optimize;
  private List<String> trueConditionNames;
  private boolean useInternalBidiFlipper;
  private boolean swapLtrRtlInUrl;
  private boolean swapLeftRightInUrl;
  private boolean simplifyCss;
  private boolean eliminateDeadStyles;
  private boolean allowUnrecognizedFunctions;
  private Set<String> allowedNonStandardFunctions;
  private boolean allowUnrecognizedProperties;
  private Set<String> allowedUnrecognizedProperties;
  private Vendor vendor;
  private boolean allowKeyframes;
  private boolean allowWebkitKeyframes;
  private boolean processDependencies;
  private String cssRenamingPrefix;
  private List<String> excludedClassesFromRenaming;
  private GssFunctionMapProvider gssFunctionMapProvider;
  private SubstitutionMapProvider cssSubstitutionMapProvider;
  private OutputRenamingMapFormat outputRenamingMapFormat;
  private boolean preserveComments;

  private JobDescription job = null;

  public JobDescriptionBuilder() {
    this.inputs = Lists.newArrayList();
    this.copyrightNotice = null;
    this.outputFormat = OutputFormat.COMPRESSED;
    this.inputOrientation = InputOrientation.LTR;
    this.outputOrientation = OutputOrientation.LTR;
    this.optimize = OptimizeStrategy.SAFE;
    this.trueConditionNames = Lists.newArrayList();
    this.useInternalBidiFlipper = false;
    this.swapLtrRtlInUrl = false;
    this.swapLeftRightInUrl = false;
    this.simplifyCss = false;
    this.eliminateDeadStyles = false;
    this.allowUnrecognizedFunctions = false;
    this.allowedNonStandardFunctions = Sets.newHashSet();
    this.allowUnrecognizedProperties = false;
    this.allowedUnrecognizedProperties = Sets.newHashSet();
    this.vendor = null;
    this.allowKeyframes = true;
    this.allowWebkitKeyframes = true;
    this.processDependencies = false;
    this.cssRenamingPrefix = "";
    this.excludedClassesFromRenaming = Lists.newArrayList();
    this.gssFunctionMapProvider = null;
    this.cssSubstitutionMapProvider = null;
    this.outputRenamingMapFormat = OutputRenamingMapFormat.JSCOMP_VARIABLE_MAP;
  }

  public JobDescriptionBuilder copyFrom(JobDescription jobToCopy) {
    setInputs(Lists.newArrayList(jobToCopy.inputs));
    this.copyrightNotice = jobToCopy.copyrightNotice;
    setOutputFormat(jobToCopy.outputFormat);
    setInputOrientation(jobToCopy.inputOrientation);
    setOutputOrientation(jobToCopy.outputOrientation);
    this.optimize = jobToCopy.optimize;
    setTrueConditionNames(Lists.newArrayList(jobToCopy.trueConditionNames));
    this.useInternalBidiFlipper = jobToCopy.useInternalBidiFlipper;
    this.swapLtrRtlInUrl = jobToCopy.swapLtrRtlInUrl;
    this.swapLeftRightInUrl = jobToCopy.swapLeftRightInUrl;
    this.simplifyCss = jobToCopy.simplifyCss;
    this.eliminateDeadStyles = jobToCopy.eliminateDeadStyles;
    this.allowUnrecognizedFunctions = jobToCopy.allowUnrecognizedFunctions;
    this.allowedNonStandardFunctions =
        ImmutableSet.copyOf(jobToCopy.allowedNonStandardFunctions);
    this.allowUnrecognizedProperties = jobToCopy.allowUnrecognizedProperties;
    this.allowedUnrecognizedProperties =
        ImmutableSet.copyOf(jobToCopy.allowedUnrecognizedProperties);
    this.vendor = jobToCopy.vendor;
    this.allowKeyframes = jobToCopy.allowKeyframes;
    this.allowWebkitKeyframes = jobToCopy.allowWebkitKeyframes;
    this.cssRenamingPrefix = jobToCopy.cssRenamingPrefix;
    setExcludedClassesFromRenaming(
        ImmutableList.copyOf(jobToCopy.excludedClassesFromRenaming));
    this.gssFunctionMapProvider = jobToCopy.gssFunctionMapProvider;
    this.cssSubstitutionMapProvider = jobToCopy.cssSubstitutionMapProvider;
    this.outputRenamingMapFormat = jobToCopy.outputRenamingMapFormat;
    return this;
  }

  private void checkJobIsNotAlreadyCreated() {
    Preconditions.checkState(job == null, "You cannot set job properties " +
        "after the message was created.");
  }

  public JobDescriptionBuilder clearInputs() {
    checkJobIsNotAlreadyCreated();
    this.inputs.clear();
    return this;
  }

  public JobDescriptionBuilder setInputs(List<SourceCode> newInputs) {
    checkJobIsNotAlreadyCreated();<commit_msg>Added preserve_comments opt into job copy and cmd line integration test ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=77687974<commit_after>/*
 * Copyright 2008 Google Inc.
 *
 * 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.common.css;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.css.JobDescription.InputOrientation;
import com.google.common.css.JobDescription.OptimizeStrategy;
import com.google.common.css.JobDescription.OutputFormat;
import com.google.common.css.JobDescription.OutputOrientation;

import java.util.List;
import java.util.Set;

/**
 * Aids in the creation of inputs for the compiler. A builder can be used for
 * creating a single {@link JobDescription}.
 *
 */
public class JobDescriptionBuilder {
  private List<SourceCode> inputs;
  private String copyrightNotice;
  private OutputFormat outputFormat;
  private InputOrientation inputOrientation;
  private OutputOrientation outputOrientation;
  private OptimizeStrategy optimize;
  private List<String> trueConditionNames;
  private boolean useInternalBidiFlipper;
  private boolean swapLtrRtlInUrl;
  private boolean swapLeftRightInUrl;
  private boolean simplifyCss;
  private boolean eliminateDeadStyles;
  private boolean allowUnrecognizedFunctions;
  private Set<String> allowedNonStandardFunctions;
  private boolean allowUnrecognizedProperties;
  private Set<String> allowedUnrecognizedProperties;
  private Vendor vendor;
  private boolean allowKeyframes;
  private boolean allowWebkitKeyframes;
  private boolean processDependencies;
  private String cssRenamingPrefix;
  private List<String> excludedClassesFromRenaming;
  private GssFunctionMapProvider gssFunctionMapProvider;
  private SubstitutionMapProvider cssSubstitutionMapProvider;
  private OutputRenamingMapFormat outputRenamingMapFormat;
  private boolean preserveComments;

  private JobDescription job = null;

  public JobDescriptionBuilder() {
    this.inputs = Lists.newArrayList();
    this.copyrightNotice = null;
    this.outputFormat = OutputFormat.COMPRESSED;
    this.inputOrientation = InputOrientation.LTR;
    this.outputOrientation = OutputOrientation.LTR;
    this.optimize = OptimizeStrategy.SAFE;
    this.trueConditionNames = Lists.newArrayList();
    this.useInternalBidiFlipper = false;
    this.swapLtrRtlInUrl = false;
    this.swapLeftRightInUrl = false;
    this.simplifyCss = false;
    this.eliminateDeadStyles = false;
    this.allowUnrecognizedFunctions = false;
    this.allowedNonStandardFunctions = Sets.newHashSet();
    this.allowUnrecognizedProperties = false;
    this.allowedUnrecognizedProperties = Sets.newHashSet();
    this.vendor = null;
    this.allowKeyframes = true;
    this.allowWebkitKeyframes = true;
    this.processDependencies = false;
    this.cssRenamingPrefix = "";
    this.excludedClassesFromRenaming = Lists.newArrayList();
    this.gssFunctionMapProvider = null;
    this.cssSubstitutionMapProvider = null;
    this.outputRenamingMapFormat = OutputRenamingMapFormat.JSCOMP_VARIABLE_MAP;
    this.preserveComments = false;
  }

  public JobDescriptionBuilder copyFrom(JobDescription jobToCopy) {
    setInputs(Lists.newArrayList(jobToCopy.inputs));
    this.copyrightNotice = jobToCopy.copyrightNotice;
    setOutputFormat(jobToCopy.outputFormat);
    setInputOrientation(jobToCopy.inputOrientation);
    setOutputOrientation(jobToCopy.outputOrientation);
    this.optimize = jobToCopy.optimize;
    setTrueConditionNames(Lists.newArrayList(jobToCopy.trueConditionNames));
    this.useInternalBidiFlipper = jobToCopy.useInternalBidiFlipper;
    this.swapLtrRtlInUrl = jobToCopy.swapLtrRtlInUrl;
    this.swapLeftRightInUrl = jobToCopy.swapLeftRightInUrl;
    this.simplifyCss = jobToCopy.simplifyCss;
    this.eliminateDeadStyles = jobToCopy.eliminateDeadStyles;
    this.allowUnrecognizedFunctions = jobToCopy.allowUnrecognizedFunctions;
    this.allowedNonStandardFunctions =
        ImmutableSet.copyOf(jobToCopy.allowedNonStandardFunctions);
    this.allowUnrecognizedProperties = jobToCopy.allowUnrecognizedProperties;
    this.allowedUnrecognizedProperties =
        ImmutableSet.copyOf(jobToCopy.allowedUnrecognizedProperties);
    this.vendor = jobToCopy.vendor;
    this.allowKeyframes = jobToCopy.allowKeyframes;
    this.allowWebkitKeyframes = jobToCopy.allowWebkitKeyframes;
    this.cssRenamingPrefix = jobToCopy.cssRenamingPrefix;
    setExcludedClassesFromRenaming(
        ImmutableList.copyOf(jobToCopy.excludedClassesFromRenaming));
    this.gssFunctionMapProvider = jobToCopy.gssFunctionMapProvider;
    this.cssSubstitutionMapProvider = jobToCopy.cssSubstitutionMapProvider;
    this.outputRenamingMapFormat = jobToCopy.outputRenamingMapFormat;
    this.preserveComments = jobToCopy.preserveComments;
    return this;
  }

  private void checkJobIsNotAlreadyCreated() {
    Preconditions.checkState(job == null, "You cannot set job properties " +
        "after the message was created.");
  }

  public JobDescriptionBuilder clearInputs() {
    checkJobIsNotAlreadyCreated();
    this.inputs.clear();
    return this;
  }

  public JobDescriptionBuilder setInputs(List<SourceCode> newInputs) {
    checkJobIsNotAlreadyCreated();
{'fraction_non_alphanumeric': 0.07345460815587551, 'fraction_numerical': 0.002069143891714803, 'mean_word_length': 5.105263157894737, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3829047', 'n_tokens_mistral': 3281, 'n_tokens_neox': 3149, 'n_words': 698}