You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/10/25 08:29:38 UTC
svn commit: r829504 - in /commons/sandbox/runtime/trunk: ./ src/ant/
src/main/native/build/org/ src/main/native/build/org/apache/
src/main/native/build/org/apache/commons/
src/main/native/build/org/apache/commons/runtime/
src/main/native/include/arch/w...
Author: mturk
Date: Sun Oct 25 07:29:37 2009
New Revision: 829504
URL: http://svn.apache.org/viewvc?rev=829504&view=rev
Log:
Move ant tasks inside native/build. They are native build helpers anyhow
Added:
commons/sandbox/runtime/trunk/src/main/native/build/org/
commons/sandbox/runtime/trunk/src/main/native/build/org/apache/
commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/
commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/
commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/SystemIdTask.java (with props)
commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/UuidTask.java (with props)
Removed:
commons/sandbox/runtime/trunk/src/ant/
Modified:
commons/sandbox/runtime/trunk/build.xml
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
Modified: commons/sandbox/runtime/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/build.xml?rev=829504&r1=829503&r2=829504&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/build.xml (original)
+++ commons/sandbox/runtime/trunk/build.xml Sun Oct 25 07:29:37 2009
@@ -72,7 +72,7 @@
<!-- Ant tasks classpath -->
<path id="task.classpath">
- <pathelement location="${build.dest}/ant"/>
+ <pathelement location="${build.dest}/build"/>
</path>
<!-- Examples classpath -->
@@ -152,17 +152,17 @@
<!-- Compiles the ant task directory -->
<!-- =================================================================== -->
<target name="tasks" depends="prepare">
- <mkdir dir="${build.dest}/ant"/>
- <mkdir dir="${build.src}/ant"/>
- <copy todir="${build.src}/ant" filtering="yes">
- <fileset dir="${src.dir}/ant">
+ <mkdir dir="${build.dest}/build"/>
+ <mkdir dir="${build.src}/build"/>
+ <copy todir="${build.src}/build" filtering="yes">
+ <fileset dir="${runtime.natives.path}/build">
<include name="**/*.java"/>
<include name="**/*.xml"/>
<include name="**/*.properties"/>
</fileset>
</copy>
- <javac srcdir="${build.src}/ant"
- destdir="${build.dest}/ant"
+ <javac srcdir="${build.src}/build"
+ destdir="${build.dest}/build"
debug="${compile.debug}"
source="${compile.source}"
target="${compile.target}"
Added: commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/SystemIdTask.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/SystemIdTask.java?rev=829504&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/SystemIdTask.java (added)
+++ commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/SystemIdTask.java Sun Oct 25 07:29:37 2009
@@ -0,0 +1,180 @@
+/* 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.
+ */
+package org.apache.commons.runtime;
+
+import java.util.Properties;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+/**
+ * Apache Ant task for setting the {@code SystemId} properties.
+ * <p>
+ * The task is used in {@code build.xml} for setting the same
+ * names later used for extracting the native libraries.
+ * </p>
+ */
+public class SystemIdTask extends Task
+{
+ private String prefix;
+ private static Properties props;
+
+ static {
+ props = System.getProperties();
+ }
+
+ /* Copy of the {@code SystemId.getSysname} method.
+ * Make sure those methods are in sync!
+ */
+ private static String getSysname()
+ {
+ String name = props.getProperty("os.name");
+ String platform = "unknown";
+
+ if (name.startsWith("Windows"))
+ platform = "windows";
+ else if (name.startsWith("Mac OS"))
+ platform = "darwin";
+ else if (name.endsWith("BSD"))
+ platform = "bsd";
+ else if (name.equals("Linux"))
+ platform = "linux";
+ else if (name.equals("Solaris"))
+ platform = "solaris";
+ else if (name.equals("SunOS"))
+ platform = "solaris";
+ else if (name.equals("HP-UX"))
+ platform = "hpux";
+ else if (name.equals("AIX"))
+ platform = "aix";
+
+ return platform;
+ }
+
+ /* Copy of the {@code SystemId.getDataModel} method.
+ * Make sure those methods are in sync!
+ */
+ private static String getDataModel()
+ {
+ String data = props.getProperty("sun.arch.data.model");
+
+ if (data == null) {
+ data = props.getProperty("com.ibm.vm.bitmode");
+ }
+ if (data == null) {
+ String arch = props.getProperty("os.arch");
+ if (arch.indexOf("64") < 0) {
+ /* TODO: Investigate other JVM's property for
+ * figuring the data model (32 or 64)
+ */
+ data = "32";
+ }
+ else {
+ data = "64";
+ }
+ }
+ return data;
+ }
+
+ /* Copy of the {@code SystemId.getProcessor} method.
+ * Make sure those methods are in sync!
+ */
+ private static String getProcessor()
+ {
+ String cpu;
+ String name = props.getProperty("os.name");
+ String arch = props.getProperty("os.arch");
+ String data = getDataModel();
+
+ if (arch.endsWith("86")) {
+ cpu = "x86";
+ if (name.startsWith("Mac OS")) {
+ if (data.equals("64"))
+ cpu = "x86_64";
+ }
+ }
+ else if (arch.startsWith("PA_RISC")) {
+ if (data.equals("64"))
+ cpu = "parisc64";
+ else
+ cpu = "parisc";
+ }
+ else if (arch.startsWith("IA64"))
+ cpu = "ia64";
+ else if (arch.startsWith("sparc")) {
+ if (data.equals("64"))
+ cpu = "sparc64";
+ else
+ cpu = "sparc";
+ }
+ else if (arch.startsWith("ppc")) {
+ if (data.equals("64"))
+ cpu = "ppc64";
+ else
+ cpu = "ppc";
+ }
+ else if (arch.equals("amd64"))
+ cpu = "x86_64";
+ else
+ cpu = arch;
+ return cpu;
+ }
+
+ /* Copy of the {@code SystemId.getSoExtension} method.
+ * Make sure those methods are in sync!
+ */
+ private static String getSoExtension()
+ {
+ String sys = getSysname();
+ String ext;
+
+ if (sys.equals("windows")) {
+ ext = "dll";
+ }
+ else if (sys.equals("darwin")) {
+ ext = "jnilib";
+ }
+ else if (sys.equals("hpux")) {
+ if (getProcessor().startsWith("parisc"))
+ ext = "sl";
+ else
+ ext = "so";
+ }
+ else {
+ ext = "so";
+ }
+ /* TODO: Check if this matches the System.mapLibraryName()
+ */
+ return ext;
+ }
+
+ public void setPrefix(String prefix)
+ {
+ this.prefix = prefix;
+ }
+
+ public void execute()
+ throws BuildException
+ {
+ if (prefix == null)
+ throw new BuildException("Missing prefix attribute");
+ getProject().setNewProperty(prefix + ".so", getSoExtension());
+ getProject().setNewProperty(prefix + ".cpu", getProcessor());
+ getProject().setNewProperty(prefix + ".os", getSysname());
+ getProject().setNewProperty(prefix + ".data.model", getDataModel());
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/SystemIdTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/UuidTask.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/UuidTask.java?rev=829504&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/UuidTask.java (added)
+++ commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/UuidTask.java Sun Oct 25 07:29:37 2009
@@ -0,0 +1,78 @@
+/* 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.
+ */
+package org.apache.commons.runtime;
+
+import java.util.Random;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+/**
+ * Apache Ant task for setting the {@code UUID} property.
+ */
+public class UuidTask extends Task
+{
+ private String property;
+
+ public void setProperty(String property)
+ {
+ this.property = property;
+ }
+
+ private String hex(byte val)
+ {
+ String h = Integer.toHexString(val);
+ if (h.length() == 1)
+ h = "0" + h;
+ return h.substring(h.length() - 2);
+ }
+
+ public void execute()
+ throws BuildException
+ {
+ if (property == null)
+ throw new BuildException("Missing property attribute");
+ byte [] uuid = new byte[16];
+ Random random = new Random(System.currentTimeMillis());
+ random.nextBytes(uuid);
+
+ // "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
+ StringBuffer sb = new StringBuffer();
+ sb.append(hex(uuid[0]));
+ sb.append(hex(uuid[1]));
+ sb.append(hex(uuid[2]));
+ sb.append(hex(uuid[3]));
+ sb.append('-');
+ sb.append(hex(uuid[4]));
+ sb.append(hex(uuid[5]));
+ sb.append('-');
+ sb.append(hex(uuid[6]));
+ sb.append(hex(uuid[7]));
+ sb.append('-');
+ sb.append(hex(uuid[8]));
+ sb.append(hex(uuid[9]));
+ sb.append('-');
+ sb.append(hex(uuid[10]));
+ sb.append(hex(uuid[11]));
+ sb.append(hex(uuid[12]));
+ sb.append(hex(uuid[13]));
+ sb.append(hex(uuid[14]));
+ sb.append(hex(uuid[15]));
+
+ getProject().setNewProperty(property, sb.toString());
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/build/org/apache/commons/runtime/UuidTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=829504&r1=829503&r2=829504&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Sun Oct 25 07:29:37 2009
@@ -27,6 +27,7 @@
#include <iphlpapi.h>
#include <userenv.h>
#include <shellapi.h>
+#include <shlwapi.h>
#include <winioctl.h>
#include <wtsapi32.h>
#include <wincrypt.h>
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c?rev=829504&r1=829503&r2=829504&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c Sun Oct 25 07:29:37 2009
@@ -49,7 +49,7 @@
while (path[nd] == '.')
nd++;
if (nd > 2) {
- errno = ACR_EINVAL;
+ errno = ACR_EBADPATH;
return NULL;
}
if (IS_PATH_SEP(path[nd])) {
@@ -115,7 +115,7 @@
while (path[nd] == '.')
nd++;
if (nd > 2) {
- errno = ACR_EINVAL;
+ errno = ACR_EBADPATH;
return NULL;
}
if (IS_PATH_SEP(path[nd])) {
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c?rev=829504&r1=829503&r2=829504&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c Sun Oct 25 07:29:37 2009
@@ -41,7 +41,7 @@
static __inline wchar_t *NO2UNC(wchar_t *fname)
{
if (fname[0] == L'/' && fname[1] == L'/' &&
- fname[2] == L'?' && fname[2] == L'/') {
+ fname[2] == L'?' && fname[3] == L'/') {
fname += 4;
if (fname[0] == L'U' && fname[1] == L'N' &&
fname[2] == L'C' && fname[3] == L'/') {
@@ -77,7 +77,6 @@
}
}
-static int case_sensitive = 0;
#define IS_PATH_SEP(C) ((C) == L'/' || (C) == L'\0')
#define IS_DRIVE_CHAR(C) (((C) >= L'A' && (C) <= L'Z') || \
((C) >= L'a' && (C) <= L'z'))
@@ -89,7 +88,22 @@
int ch = '/';
size_t l;
- wcslcpy(pcopy, path, size);
+ if (wcschr(path, L'%')) {
+ /* Try to unexpand the path
+ */
+ l = ExpandEnvironmentStringsW(path, pcopy, (DWORD)size);
+ if (l == 0 || l > size) {
+ ACR_SET_OS_ERROR(ACR_EOVERFLOW);
+ return NULL;
+ }
+ }
+ else {
+ l = wcslcpy(pcopy, path, size);
+ if (l > size) {
+ ACR_SET_OS_ERROR(ACR_EOVERFLOW);
+ return NULL;
+ }
+ }
/* Convert everything to foward slashes
*/
BS2FS(pcopy);
@@ -97,14 +111,36 @@
*/
pcopy = NO2UNC(pcopy);
l = wcslen(pcopy);
- /* Remove any trailing slash unless this is
- * a single slash path.
- */
- if (l > 1 && pcopy[l - 1] == L'/')
- pcopy[l - 1] = L'\0';
+ if (l == 0) {
+ /* Empty path
+ */
+ ACR_SET_OS_ERROR(ACR_EBADPATH);
+ return NULL;
+ }
+ else if (l == 1) {
+ if (pcopy[0] == L' ') {
+ /* Single Trailing space is invalid path
+ */
+ ACR_SET_OS_ERROR(ACR_EBADPATH);
+ return NULL;
+ }
+ }
+ else {
+ /* Remove any trailing slash unless this is
+ * a single slash path.
+ */
+ if (pcopy[l - 1] == L'/')
+ pcopy[--l] = L'\0';
+ else if (pcopy[l - 1] == L' ' || pcopy[l - 1] == L'.') {
+ /* Trailing space and dot are invalid file or dir names
+ */
+ ACR_SET_OS_ERROR(ACR_EBADPATH);
+ return NULL;
+ }
+ }
rv = pcopy;
- if (IS_DRIVE_CHAR(pcopy[0]) && pcopy[1] == L':') {
+ if (l > 1 && pcopy[1] == L':' && IS_DRIVE_CHAR(pcopy[0])) {
/* Never go above C: */
pcopy += 2;
}
@@ -112,7 +148,7 @@
/* Never go above //share/
*/
if (pcopy[2] == L'.' && pcopy[3] == L'/') {
- /* This is //./pipe/ */
+ /* This is probably //./pipe/ */
return pcopy;
}
cp = wcschr(pcopy + 2, '/');
@@ -131,7 +167,7 @@
while (path[nd] == L'.')
nd++;
if (nd > 2) {
- ACR_SET_OS_ERROR(ACR_EINVAL);
+ ACR_SET_OS_ERROR(ACR_EBADPATH);
return NULL;
}
if (IS_PATH_SEP(path[nd])) {
@@ -159,10 +195,8 @@
ch = *cp++ = *path++;
}
*cp = L'\0';
- /* Duplicate the final path
- */
- return rv;
+ return rv;
}
wchar_t * acr_GetJavaNativePathW(JNIEnv *_E, jstring str, wchar_t *b)
@@ -256,9 +290,10 @@
memcpy(retstr, srcstr, srclen * sizeof(wchar_t));
}
+ (*_E)->ReleaseStringCritical(_E, str, sr);
rv[retlen] = L'\0';
FS2BS(retstr);
- (*_E)->ReleaseStringCritical(_E, str, sr);
+
return rv;
}
@@ -356,28 +391,16 @@
jintArray p)
{
jint ia[8];
- DWORD dw;
+
UNREFERENCED_O;
ia[0] = '\\';
ia[1] = ';';
- ia[2] = ACR_PPATH_MAX - 1; /* Use our path limit */
+ ia[2] = ACR_PPATH_MAX - 1; /* Use our path limit */
ia[3] = MAX_PATH - 2;
- if (GetVolumeInformationW(L"C:\\",
- NULL,
- 0,
- NULL,
- NULL,
- &dw,
- NULL,
- 0)) {
- if ((dw & (FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES)) ==
- (FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES))
- case_sensitive = 1;
- }
- ia[4] = case_sensitive;
+ ia[4] = 0; /* Case insensitive FS */
ia[5] = '%';
- ia[6] = '%';
+
(*_E)->SetIntArrayRegion(_E, p, 0, 8, &ia[0]);
}
@@ -415,32 +438,11 @@
jstring other)
{
int rc = 1;
- int uc = case_sensitive;
- DWORD dw;
UNREFERENCED_O;
WITH_WSTR(path) {
WITH_WSTR(other) {
- /* XXX: We could catch instead doing volume check each time.
- */
- if (GetVolumeInformationW(J2W(path),
- NULL,
- 0,
- NULL,
- NULL,
- &dw,
- NULL,
- 0)) {
- if ((dw & (FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES)) ==
- (FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES))
- uc = 1;
- else
- uc = 0;
- }
- if (uc)
- rc = wcscmp(J2W(path), J2W(other));
- else
- rc = _wcsicmp(J2W(path), J2W(other));
+ rc = _wcsicmp(J2W(path), J2W(other));
} END_WITH_WSTR(other);
} END_WITH_WSTR(path);
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=829504&r1=829503&r2=829504&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Sun Oct 25 07:29:37 2009
@@ -331,7 +331,7 @@
{
String [] paths = {
"/",
- "\\\\",
+ "\\\\?\\",
"foo/",
"/foo/",
"/foo/bar",
@@ -342,6 +342,7 @@
"c:/foo/../../../bar",
"//share/foo/../../../bar",
"//./pipe/foo/../../../bar",
+ "%USERPROFILE%/bar"
};
for (int i = 0; i < paths.length; i++) {
Path p = new Path(paths[i]);