|
| 1 | +package de.oppermann.pomutils.rules; |
| 2 | + |
| 3 | +import de.oppermann.pomutils.select.SelectionStrategy; |
| 4 | +import de.oppermann.pomutils.util.POM; |
| 5 | +import de.oppermann.pomutils.util.VersionFieldType; |
| 6 | +import org.slf4j.Logger; |
| 7 | +import org.slf4j.LoggerFactory; |
| 8 | + |
| 9 | +/* |
| 10 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 11 | + * or more contributor license agreements. See the NOTICE file |
| 12 | + * distributed with this work for additional information |
| 13 | + * regarding copyright ownership. The ASF licenses this file |
| 14 | + * to you under the Apache License, Version 2.0 (the |
| 15 | + * "License"); you may not use this file except in compliance |
| 16 | + * with the License. You may obtain a copy of the License at |
| 17 | + * |
| 18 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | + * |
| 20 | + * Unless required by applicable law or agreed to in writing, |
| 21 | + * software distributed under the License is distributed on an |
| 22 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 23 | + * KIND, either express or implied. See the License for the |
| 24 | + * specific language governing permissions and limitations |
| 25 | + * under the License. |
| 26 | + */ |
| 27 | + |
| 28 | +/** |
| 29 | + * |
| 30 | + * @author Sébastien Latre |
| 31 | + * |
| 32 | + */ |
| 33 | + |
| 34 | +public class ScmTagRule extends AbstractRule { |
| 35 | + |
| 36 | + private final Logger logger = LoggerFactory.getLogger(ScmTagRule.class); |
| 37 | + |
| 38 | + public ScmTagRule() { |
| 39 | + // for creating this instance via snakeyaml |
| 40 | + } |
| 41 | + |
| 42 | + public ScmTagRule(SelectionStrategy strategy) { |
| 43 | + super(strategy); |
| 44 | + logger.debug("Using ScmTagRule with strategy [{}]", strategy.toString()); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void evaluate(POM basePom, POM ourPom, POM theirPom) { |
| 49 | + String baseScmTag = basePom.getScmTag(); |
| 50 | + String ourScmTag = ourPom.getScmTag(); |
| 51 | + String theirScmTag = theirPom.getScmTag(); |
| 52 | + if (baseScmTag != null && ourScmTag != null && theirScmTag != null && !ourScmTag.equals(theirScmTag)) { |
| 53 | + String newScmTag; |
| 54 | + if (baseScmTag.equals(ourScmTag)) { |
| 55 | + /* |
| 56 | + * Our ScmTag hasn't changed, so no conflict. Just use theirScmTag. |
| 57 | + */ |
| 58 | + newScmTag = theirScmTag; |
| 59 | + } else if (baseScmTag.equals(theirScmTag)) { |
| 60 | + /* |
| 61 | + * Their scmTag hasn't changed, so no conflict. Just use ourScmTag. |
| 62 | + */ |
| 63 | + newScmTag = ourScmTag; |
| 64 | + } else { |
| 65 | + /* |
| 66 | + * Both our scmTag and their scmTag have changed from the base, so conflict. |
| 67 | + */ |
| 68 | + switch (getStrategy()) { |
| 69 | + case OUR: |
| 70 | + newScmTag = ourScmTag; |
| 71 | + break; |
| 72 | + case THEIR: |
| 73 | + newScmTag = theirScmTag; |
| 74 | + break; |
| 75 | + default: |
| 76 | + throw new IllegalArgumentException("Strategy [" + getStrategy().toString() + "] not implemented."); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + if (newScmTag != null) { |
| 81 | + /* |
| 82 | + * newScmTag can be null if the user wants to skip resolution. |
| 83 | + */ |
| 84 | + |
| 85 | + POM pomToAdjust = newScmTag.equals(ourScmTag) |
| 86 | + ? theirPom |
| 87 | + : ourPom; |
| 88 | + |
| 89 | + pomToAdjust.setScmTag(newScmTag); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments