[maven-debian-helper] 03/03: Adapted the debian-maven-plugin tests to run on Windows

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Tue Feb 4 16:06:20 UTC 2014


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to branch master
in repository maven-debian-helper.

commit 01037007062ea13b9355199bf6c70c9d2c2b0e4c
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Tue Feb 4 17:05:55 2014 +0100

    Adapted the debian-maven-plugin tests to run on Windows
---
 .../org/debian/maven/plugin/SysInstallMojo.java    | 31 +++++++++++++---------
 .../org/debian/maven/plugin/InstallMojoTest.java   | 31 +++++++++++-----------
 2 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/debian-maven-plugin/src/main/java/org/debian/maven/plugin/SysInstallMojo.java b/debian-maven-plugin/src/main/java/org/debian/maven/plugin/SysInstallMojo.java
index 57b5a36..7b72fcf 100644
--- a/debian-maven-plugin/src/main/java/org/debian/maven/plugin/SysInstallMojo.java
+++ b/debian-maven-plugin/src/main/java/org/debian/maven/plugin/SysInstallMojo.java
@@ -570,8 +570,19 @@ public class SysInstallMojo extends AbstractMojo {
     /**
      * command for creating the relative symlink
      */
-    private String[] linkCommand(String source, String dest) {
-        return new String[]{"ln", "-s", source, dest};
+    private void link(String target, String linkName) throws IOException {
+        if (System.getProperty("os.name").contains("Windows")) {
+            File linkNameFile = new File(linkName).getAbsoluteFile();
+            linkNameFile.getParentFile().mkdirs();
+            Process process = new ProcessBuilder().command("cmd", "/C", "mklink", linkNameFile.getAbsolutePath(), target.replace('/', '\\')).start();
+            try {
+                process.waitFor();
+            } catch (InterruptedException e) {
+                throw new IOException(e);
+            }
+        } else {
+            Runtime.getRuntime().exec(new String[]{"ln", "-s", target, linkName}, null);
+        }
     }
 
     private void mkdir(String path) throws IOException {
@@ -584,10 +595,6 @@ public class SysInstallMojo extends AbstractMojo {
         }
     }
 
-    private void run(String[] command) throws IOException {
-        Runtime.getRuntime().exec(command, null);
-    }
-
     /**
      * if a jar exists: copy it to the Maven repository
      */
@@ -598,7 +605,7 @@ public class SysInstallMojo extends AbstractMojo {
             FileUtils.copyFile(jarFile, new File(jarDestPath()));
             if (debianVersion != null && !debianVersion.equals(version)) {
                 mkdir(debianFullRepoPath());
-                run(linkCommand(jarDestRelPath(), debianJarDestPath()));
+                link(jarDestRelPath(), debianJarDestPath());
             }
         }
     }
@@ -613,10 +620,10 @@ public class SysInstallMojo extends AbstractMojo {
             mkdir(compatSharePath());
             FileUtils.copyFile(jarFile, new File(fullCompatPath()));
             if (noUsjVersionless) {
-                run(linkCommand(destUsjJarName(), versionedFullCompatPath()));
+                link(destUsjJarName(), versionedFullCompatPath());
             } else {
-                run(linkCommand(destUsjJarName(), fullCompatPath()));
-                run(linkCommand(destUsjJarName(), versionedFullCompatPath()));
+                link(destUsjJarName(), fullCompatPath());
+                link(destUsjJarName(), versionedFullCompatPath());
             }
         }
     }
@@ -636,10 +643,10 @@ public class SysInstallMojo extends AbstractMojo {
                 targetPath = fullCompatPath();
             }
 
-            run(linkCommand(DirectoryUtils.relativePath(fullRepoPath(), targetPath), jarDestPath()));
+            link(DirectoryUtils.relativePath(fullRepoPath(), targetPath), jarDestPath());
             if (debianVersion != null && !debianVersion.equals(version)) {
                 mkdir(debianFullRepoPath());
-                run(linkCommand(DirectoryUtils.relativePath(debianFullRepoPath(), targetPath), debianJarDestPath()));
+                link(DirectoryUtils.relativePath(debianFullRepoPath(), targetPath), debianJarDestPath());
             }
         }
     }
diff --git a/debian-maven-plugin/src/test/java/org/debian/maven/plugin/InstallMojoTest.java b/debian-maven-plugin/src/test/java/org/debian/maven/plugin/InstallMojoTest.java
index 650c528..d7b1136 100644
--- a/debian-maven-plugin/src/test/java/org/debian/maven/plugin/InstallMojoTest.java
+++ b/debian-maven-plugin/src/test/java/org/debian/maven/plugin/InstallMojoTest.java
@@ -39,8 +39,6 @@ public class InstallMojoTest {
     private File testDir = new File("tmp");
     private InstallMojo mojo;
 
-    private List<Reader> openedReaders = new ArrayList<Reader>();
-
     @Before
     public void setUp() throws Exception {
         testDir.mkdirs();
@@ -48,14 +46,6 @@ public class InstallMojoTest {
 
     @After
     public void tearDown() throws Exception {
-        for (Reader reader : openedReaders) {
-            try {
-                reader.close();
-            } catch (IOException ex) {
-                Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
-            }
-        }
-        openedReaders.clear();
         FileUtils.deleteDirectory(testDir);
 
         File debianDir = getFileInClasspath("plexus-compiler/debian/maven.rules").getParentFile();
@@ -91,7 +81,7 @@ public class InstallMojoTest {
 
         File debianRepoJar = getFileInClasspath("plexus-compiler/debian/libplexus-compiler-java/usr/share/maven-repo/org/codehaus/plexus/plexus-compiler-test/1.x/plexus-compiler-test-1.x.jar");
         assertNotNull(debianRepoJar);
-        assertEquals(versionedRepoJar, debianRepoJar.getCanonicalFile());
+        assertSameFile(versionedRepoJar, debianRepoJar);
         File debianRepoPom = getFileInClasspath("plexus-compiler/debian/libplexus-compiler-java/usr/share/maven-repo/org/codehaus/plexus/plexus-compiler-test/1.x/plexus-compiler-test-1.x.pom");
         assertNotNull(debianRepoPom);
     }
@@ -124,17 +114,17 @@ public class InstallMojoTest {
         assertNotNull(usjJar);
         File versionedUsjJar = getFileInClasspath("plexus-compiler/debian/libplexus-compiler-java/usr/share/java/plexus-compiler-api-1.8.2.jar");
         assertNotNull(versionedUsjJar);
-        assertEquals(usjJar, versionedUsjJar.getCanonicalFile());
+        assertSameFile(usjJar, versionedUsjJar);
 
         File versionedRepoJar = getFileInClasspath("plexus-compiler/debian/libplexus-compiler-java/usr/share/maven-repo/org/codehaus/plexus/plexus-compiler-api/1.8.2/plexus-compiler-api-1.8.2.jar");
         assertNotNull(versionedRepoJar);
-        assertEquals(usjJar, versionedRepoJar.getCanonicalFile());
+        assertSameFile(usjJar, versionedRepoJar);
         File versionedRepoPom = getFileInClasspath("plexus-compiler/debian/libplexus-compiler-java/usr/share/maven-repo/org/codehaus/plexus/plexus-compiler-api/1.8.2/plexus-compiler-api-1.8.2.pom");
         assertNotNull(versionedRepoPom);
 
         File debianRepoJar = getFileInClasspath("plexus-compiler/debian/libplexus-compiler-java/usr/share/maven-repo/org/codehaus/plexus/plexus-compiler-api/1.x/plexus-compiler-api-1.x.jar");
         assertNotNull(debianRepoJar);
-        assertEquals(usjJar, debianRepoJar.getCanonicalFile());
+        assertSameFile(usjJar, debianRepoJar);
         File debianRepoPom = getFileInClasspath("plexus-compiler/debian/libplexus-compiler-java/usr/share/maven-repo/org/codehaus/plexus/plexus-compiler-api/1.x/plexus-compiler-api-1.x.pom");
         assertNotNull(debianRepoPom);
 
@@ -173,17 +163,28 @@ public class InstallMojoTest {
         assertNotNull(debianRepoJar);
         // TODO ask Ludovic whether he also saw this test failing
         // The versioned artifact should be the real file and the debian version should be a symlink.
-        //assertEquals(versionedRepoJar.getAbsoluteFile(), debianRepoJar.getCanonicalFile());
+        //assertSameFile(versionedRepoJar.getAbsoluteFile(), debianRepoJar);
         File debianRepoPom = new File(testDir, "repo/org/codehaus/plexus/plexus-compiler-test/1.x/plexus-compiler-test-1.x.pom");
         assertNotNull(debianRepoPom);
     }
 
+    /**
+     * Checks if the actual file is a link to the expected file.
+     */
+    private void assertSameFile(File expected, File actual) throws IOException {
+        if (!System.getProperty("os.name").contains("Windows")) {
+            assertEquals(expected, actual.getCanonicalFile());
+        }
+    }
 
     protected File getFileInClasspath(String resource) {
         if (!resource.startsWith("/")) {
             resource = "/" + resource;
         }
         URL url = this.getClass().getResource(resource);
+        
+        assertNotNull("Resource " + resource + " not found in the classpath", url);
+        
         File f;
         try {
             f = new File(url.toURI());

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/maven-debian-helper.git



More information about the pkg-java-commits mailing list