001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.versionmigrator.internal; 014 015import java.util.Optional; 016import java.util.regex.Matcher; 017import java.util.regex.Pattern; 018 019import org.apache.tapestry5.versionmigrator.ClassRefactor; 020import org.apache.tapestry5.versionmigrator.FileRefactorCommitParser; 021 022/** 023 * Parses lines like this, in which just the artifact is changed: 024 * <code>{tapestry-ioc => tapestry5-annotations}/src/main/java/org/apache/tapestry5/ioc/annotations/Advise.java (100%)</code>. 025 */ 026public class ArtifactChangeRefactorCommitParser implements FileRefactorCommitParser { 027 028 final public static String EXAMPLE = "{tapestry-ioc => tapestry5-annotations}/src/main/java/org/apache/tapestry5/ioc/annotations/Advise.java"; 029 030 final private static Pattern PATTERN = 031 Pattern.compile("\\{(.*)\\s=>\\s([^}]*)}\\/([^\\.]*).*"); 032 033 @Override 034 public Optional<ClassRefactor> apply(String line) { 035 final Matcher matcher = PATTERN.matcher(line); 036 ClassRefactor move = null; 037 if (matcher.matches()) 038 { 039// System.out.printf("1(%s) 2(%s) 3(%s)\n", otherMatcher.group(1), otherMatcher.group(2), otherMatcher.group(3)); 040 final String className = FileRefactorCommitParser.extractPackageOrClassName(matcher.group(3)); 041 final String sourceArtifactName = matcher.group(1); 042 final String destinationArtifactName = matcher.group(2); 043 044 move = new ClassRefactor(className, className, sourceArtifactName, destinationArtifactName); 045 } 046 return Optional.ofNullable(move); 047 } 048 049}