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