You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2012/10/15 19:36:26 UTC
svn commit: r1398412 - in /maven/shared/trunk/maven-shared-utils/src:
main/java/org/apache/maven/shared/utils/io/
test/java/org/apache/maven/shared/utils/io/
Author: krosenvold
Date: Mon Oct 15 17:36:26 2012
New Revision: 1398412
URL: http://svn.apache.org/viewvc?rev=1398412&view=rev
Log:
o Java 7 symlink support
Added:
maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java
maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/Java7SupportTest.java
Modified:
maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java
maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java?rev=1398412&r1=1398411&r2=1398412&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanner.java Mon Oct 15 17:36:26 2012
@@ -891,6 +891,10 @@ public class DirectoryScanner
boolean isSymbolicLink( final File parent, final String name )
throws IOException
{
+ if ( Java7Support.isJava7())
+ {
+ return Java7Support.isSymLink( parent );
+ }
final File resolvedParent = new File( parent.getCanonicalPath() );
final File toTest = new File( resolvedParent, name );
return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() );
Added: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java?rev=1398412&view=auto
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java (added)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/Java7Support.java Mon Oct 15 17:36:26 2012
@@ -0,0 +1,80 @@
+package org.apache.maven.shared.utils.io;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Java7 feature detection
+ *
+ * @author Kristian Rosenvold
+ */
+public class Java7Support
+{
+
+ private static final boolean isJava7;
+
+ private static Method isSymbolicLink;
+
+ private static Method toPath;
+
+ static
+ {
+ boolean isJava7x = true;
+ try
+ {
+ Class<?> files = Class.forName( "java.nio.file.Files" );
+ Class<?> path = Class.forName( "java.nio.file.Path" );
+ isSymbolicLink = files.getMethod( "isSymbolicLink", path );
+ toPath = File.class.getMethod( "toPath" );
+ }
+ catch ( Exception e )
+ {
+ isJava7x = false;
+ }
+ isJava7 = isJava7x;
+ }
+
+ public static boolean isSymLink( File file )
+ {
+ try
+ {
+ Object path = toPath.invoke( file );
+ return (Boolean) isSymbolicLink.invoke( null, path );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new RuntimeException( e );
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+
+
+
+ public static boolean isJava7()
+ {
+ return isJava7;
+ }
+}
Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java?rev=1398412&r1=1398411&r2=1398412&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java Mon Oct 15 17:36:26 2012
@@ -142,6 +142,13 @@ public class DirectoryScannerTest
/* expExclDirs */ NONE );
}
+ public void testIsSymLin()
+ throws IOException
+ {
+ File file = new File( ".");
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.isSymbolicLink( file, "abc" );
+ }
/**
* Performs a scan and test for the given parameters if not null.
Added: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/Java7SupportTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/Java7SupportTest.java?rev=1398412&view=auto
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/Java7SupportTest.java (added)
+++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/Java7SupportTest.java Mon Oct 15 17:36:26 2012
@@ -0,0 +1,41 @@
+package org.apache.maven.shared.utils.io;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Java7SupportTest
+{
+ @Test
+ public void testIsSymLink()
+ throws Exception
+ {
+
+ File file = new File( "." );
+ if ( Java7Support.isJava7() )
+ {
+ assertFalse( Java7Support.isSymLink( file ) );
+ }
+ }
+}