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

com.redhat.ceylon.cmr.api.ArtifactOverrides Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
/*
 * Copyright 2011 Red Hat inc. and third party contributors as noted
 * by the author tags.
 * 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.redhat.ceylon.cmr.api;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

/**
 * 

Represents the overriding of an artifact. Supports:

*
    *
  • Addition and removal of dependencies
  • *
  • sharing and unsharing of dependencies
  • *
  • making dependencies optional or non-optional
  • *
  • Replacing the module entirely
  • *
* @author Ales Justin */ public class ArtifactOverrides { private static final Logger log = Logger.getLogger(ArtifactOverrides.class.getName()); private ArtifactContext owner; private Set add = new HashSet<>(); private Set remove = new HashSet<>(); private Map share = new HashMap<>(); private Map optional = new HashMap<>(); private DependencyOverride replace; private String filter; public ArtifactOverrides(ArtifactContext owner) { this.owner = owner; } public void addShareOverride(ArtifactContext context, boolean share){ this.share.put(context.getName(), share); } public void addOptionalOverride(ArtifactContext context, boolean optional){ this.optional.put(context.getName(), optional); } public boolean isShareOverridden(ArtifactContext context){ return share.containsKey(context.getName()); } public boolean isShared(ArtifactContext context){ Boolean ret = share.get(context.getName()); return ret != null && ret.booleanValue(); } public boolean isOptionalOverridden(ArtifactContext context){ return optional.containsKey(context.getName()); } public boolean isOptional(ArtifactContext context){ Boolean ret = optional.get(context.getName()); return ret != null && ret.booleanValue(); } public void addOverride(DependencyOverride override) { switch (override.getType()) { case ADD: add.add(override); break; case REMOVE: remove.add(override); break; case REPLACE: if (replace != null) { log.warning(String.format("Replace for %s is already defined: %s, current: %s", owner, replace.getArtifactContext(), override.getArtifactContext())); } replace = override; break; } } public ArtifactContext getOwner() { return owner; } public Set getAdd() { return add; } public boolean isRemoved(ArtifactContext mc) { for (DependencyOverride override : remove) { // match with optional version if (override.matches(mc)) { return true; } } return false; } public boolean isAddedOrUpdated(ArtifactContext mc) { for (DependencyOverride override : add) { // match just the name, so we can update with another version if (override.matchesName(mc)) { return true; } } return false; } public DependencyOverride getReplace() { return replace; } public String getFilter() { return filter; } void setFilter(String filter) { this.filter = filter; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy