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

com.google.gwt.dev.cfg.CombinedResourceOracle Maven / Gradle / Ivy

/*
 * Copyright 2013 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.gwt.dev.cfg;

import com.google.gwt.dev.resource.Resource;
import com.google.gwt.dev.resource.ResourceOracle;
import com.google.gwt.dev.resource.impl.AbstractResourceOracle;
import com.google.gwt.thirdparty.guava.common.collect.ImmutableSet;
import com.google.gwt.thirdparty.guava.common.collect.Maps;
import com.google.gwt.thirdparty.guava.common.collect.Sets;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Combines multiple resource oracles into a single queryable oracle.
* * Useful when the resource oracles being combined are very different in nature. For example one * that surfaces resources on disk and one that surfaces resources in a set of precompiled * libraries. */ public class CombinedResourceOracle extends AbstractResourceOracle { private Set buildResources; private Map buildResourcesByPath; private Set pathNames; private List resourceOracles; public CombinedResourceOracle(ResourceOracle... resourceOracles) { this.resourceOracles = Arrays.asList(resourceOracles); } @Override public void clear() { throw new UnsupportedOperationException("A clear/refresh life cycle is not supported."); } @Override public Set getPathNames() { if (pathNames == null) { pathNames = Sets.newHashSet(); for (ResourceOracle resourceOracle : resourceOracles) { pathNames.addAll(resourceOracle.getPathNames()); } pathNames = Collections.unmodifiableSet(pathNames); } return pathNames; } @Deprecated @Override public Map getResourceMap() { if (buildResourcesByPath == null) { buildResourcesByPath = Maps.newHashMap(); for (ResourceOracle resourceOracle : resourceOracles) { buildResourcesByPath.putAll(resourceOracle.getResourceMap()); } buildResourcesByPath = Collections.unmodifiableMap(buildResourcesByPath); } return buildResourcesByPath; } @Override public Set getResources() { if (buildResources == null) { buildResources = ImmutableSet. copyOf(getResourceMap().values()); } return buildResources; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy