Search in sources :

Example 1 with ClassRefactor

use of org.apache.tapestry5.versionmigrator.ClassRefactor in project tapestry-5 by apache.

the class PackageAndArtifactChangeRefactorCommitParser method apply.

@Override
public Optional<ClassRefactor> apply(String line) {
    ClassRefactor move = null;
    final Matcher matcher = PATTERN.matcher(line);
    if (matcher.matches()) {
        // System.out.printf("1(%s) 2(%s) 3(%s) 4(%s) 5(%s)\n", matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), matcher.group(5));
        String newPackageNameSuffix = FileRefactorCommitParser.extractPackageOrClassName(matcher.group(4));
        String oldPackageNameSuffix = FileRefactorCommitParser.extractPackageOrClassName(matcher.group(2));
        final String className = matcher.group(5);
        final String newClassName = FileRefactorCommitParser.buildClassName("", newPackageNameSuffix, className);
        final String oldClassName = FileRefactorCommitParser.buildClassName("", oldPackageNameSuffix, className);
        final String sourceArtifactName = matcher.group(1);
        final String destinationArtifactName = matcher.group(3);
        move = new ClassRefactor(newClassName, oldClassName, sourceArtifactName, destinationArtifactName);
    }
    return Optional.ofNullable(move);
}
Also used : ClassRefactor(org.apache.tapestry5.versionmigrator.ClassRefactor) Matcher(java.util.regex.Matcher)

Example 2 with ClassRefactor

use of org.apache.tapestry5.versionmigrator.ClassRefactor in project tapestry-5 by apache.

the class PackageChangeRefactorCommitParser method apply.

@Override
public Optional<ClassRefactor> apply(String line) {
    final Matcher matcher = PATTERN.matcher(line);
    ClassRefactor move = null;
    if (matcher.matches()) {
        String newPackageNameSuffix = matcher.group(4);
        String oldPackageNameSuffix = matcher.group(3);
        // System.out.printf("1(%s) 2(%s) 3(%s) 4(%s) 5(%s)\n", matcher.group(1), matcher.group(2), oldPackageNameSuffix, newPackageNameSuffix, matcher.group(5));
        final String rootPackageName = matcher.group(2).replace("src/main/java/", "").replace("/", ".");
        final String className = matcher.group(5);
        final String newClassName = FileRefactorCommitParser.buildClassName(rootPackageName, newPackageNameSuffix, className);
        final String oldClassName = FileRefactorCommitParser.buildClassName(rootPackageName, oldPackageNameSuffix, className);
        final String artifactName = matcher.group(1);
        move = new ClassRefactor(newClassName, oldClassName, artifactName, artifactName);
    }
    return Optional.ofNullable(move);
}
Also used : ClassRefactor(org.apache.tapestry5.versionmigrator.ClassRefactor) Matcher(java.util.regex.Matcher)

Example 3 with ClassRefactor

use of org.apache.tapestry5.versionmigrator.ClassRefactor in project tapestry-5 by apache.

the class ArtifactChangeRefactorCommitParserTest method valid_line.

@Test
public void valid_line() {
    // {tapestry-ioc => tapestry5-annotations}/src/main/java/org/apache/tapestry5/ioc/annotations/Advise.java
    ArtifactChangeRefactorCommitParser parser = new ArtifactChangeRefactorCommitParser();
    Optional<ClassRefactor> optionalRefactor = parser.apply(ArtifactChangeRefactorCommitParser.EXAMPLE);
    Assert.assertTrue(optionalRefactor.isPresent(), "Line not detected as a change of artifact.");
    ClassRefactor refactor = optionalRefactor.get();
    final String expectedClassName = "org.apache.tapestry5.ioc.annotations.Advise";
    Assert.assertEquals(refactor.getNewClassName(), expectedClassName);
    Assert.assertEquals(refactor.getOldClassName(), expectedClassName);
    Assert.assertEquals(refactor.getDestinationArtifact(), "tapestry5-annotations");
    Assert.assertEquals(refactor.getSourceArtifact(), "tapestry-ioc");
}
Also used : ClassRefactor(org.apache.tapestry5.versionmigrator.ClassRefactor) Test(org.testng.annotations.Test)

Example 4 with ClassRefactor

use of org.apache.tapestry5.versionmigrator.ClassRefactor in project tapestry-5 by apache.

the class PackageAndArtifactChangeRefactorCommitParserTest method valid_line.

@Test
public void valid_line() {
    // {tapestry-ioc/src/main/java/org/apache/tapestry5/ioc => commons/src/main/java/org/apache/tapestry5/commons}/ObjectProvider.java
    PackageAndArtifactChangeRefactorCommitParser parser = new PackageAndArtifactChangeRefactorCommitParser();
    Optional<ClassRefactor> optionalRefactor = parser.apply(PackageAndArtifactChangeRefactorCommitParser.EXAMPLE);
    Assert.assertTrue(optionalRefactor.isPresent(), "Line not detected as a change of package and artifact.");
    ClassRefactor refactor = optionalRefactor.get();
    Assert.assertEquals(refactor.getNewClassName(), "org.apache.tapestry5.commons.ObjectProvider");
    Assert.assertEquals(refactor.getOldClassName(), "org.apache.tapestry5.ioc.ObjectProvider");
    Assert.assertEquals(refactor.getDestinationArtifact(), "commons");
    Assert.assertEquals(refactor.getSourceArtifact(), "tapestry-ioc");
}
Also used : ClassRefactor(org.apache.tapestry5.versionmigrator.ClassRefactor) Test(org.testng.annotations.Test)

Example 5 with ClassRefactor

use of org.apache.tapestry5.versionmigrator.ClassRefactor in project tapestry-5 by apache.

the class PackageChangeRefactorCommitParserTest method valid_line.

@Test
public void valid_line() {
    // commons/src/main/java/org/apache/tapestry5/{ioc => commons}/Messages.java (98%)
    PackageChangeRefactorCommitParser parser = new PackageChangeRefactorCommitParser();
    Optional<ClassRefactor> optionalRefactor = parser.apply(PackageChangeRefactorCommitParser.EXAMPLE);
    Assert.assertTrue(optionalRefactor.isPresent(), "Line not detected as a change of package.");
    ClassRefactor refactor = optionalRefactor.get();
    Assert.assertEquals(refactor.getNewClassName(), "org.apache.tapestry5.commons.Messages");
    Assert.assertEquals(refactor.getOldClassName(), "org.apache.tapestry5.ioc.Messages");
    Assert.assertEquals(refactor.getDestinationArtifact(), "commons");
    Assert.assertEquals(refactor.getSourceArtifact(), "commons");
}
Also used : ClassRefactor(org.apache.tapestry5.versionmigrator.ClassRefactor) Test(org.testng.annotations.Test)

Aggregations

ClassRefactor (org.apache.tapestry5.versionmigrator.ClassRefactor)6 Matcher (java.util.regex.Matcher)3 Test (org.testng.annotations.Test)3 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 Formatter (java.util.Formatter)1 List (java.util.List)1 Optional (java.util.Optional)1