View Javadoc
1   package org.apache.maven.artifact.versioning;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.fail;
24  
25  import java.io.IOException;
26  import java.nio.file.FileVisitResult;
27  import java.nio.file.Files;
28  import java.nio.file.Path;
29  import java.nio.file.Paths;
30  import java.nio.file.SimpleFileVisitor;
31  import java.nio.file.attribute.BasicFileAttributes;
32  import java.util.regex.Pattern;
33  
34  import org.junit.Test;
35  
36  public class ComparableVersionIT
37  {
38  
39      @Test
40      public void test()
41          throws Exception
42      {
43          Files.walkFileTree( Paths.get( "target" ), new SimpleFileVisitor<Path>()
44          {
45              Pattern mavenArtifactJar = Pattern.compile( "maven-artifact-[\\d.]+(-SNAPSHOT)?\\.jar" );
46  
47              @Override
48              public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
49                  throws IOException
50              {
51                  String filename = file.getFileName().toString();
52                  if ( mavenArtifactJar.matcher( filename ).matches() )
53                  {
54                      Process p = Runtime.getRuntime().exec( new String[] {
55                          Paths.get( System.getProperty( "java.home" ), "bin/java" ).toString(), 
56                          "-jar",
57                          file.toAbsolutePath().toString(), 
58                          "5.32", 
59                          "5.27" } );
60  
61                      try
62                      {
63                          assertEquals( "Unexpected exit code", 0, p.waitFor() );
64                      }
65                      catch ( InterruptedException e )
66                      {
67                          fail( e.getMessage() );
68                      }
69                      return FileVisitResult.TERMINATE;
70                  }
71                  else
72                  {
73                      return FileVisitResult.CONTINUE;
74                  }
75              }
76  
77              @Override
78              public FileVisitResult preVisitDirectory( Path dir, BasicFileAttributes attrs )
79                  throws IOException
80              {
81                  if ( Paths.get( "target" ).equals( dir ) )
82                  {
83                      return FileVisitResult.CONTINUE;
84                  }
85                  else
86                  {
87                      return FileVisitResult.SKIP_SUBTREE;
88                  }
89              }
90          } );
91      }
92  
93  }