Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed Apr 13, 2012
1 parent acb6204 commit 0f2f8bb
Show file tree
Hide file tree
Showing 25 changed files with 275 additions and 69 deletions.
8 changes: 2 additions & 6 deletions build.xml
Expand Up @@ -368,13 +368,9 @@
<copy file="src/client/vertxbus.js" todir="${dist-build}/examples/javascript/webapp/web/js"/>
<copy file="src/client/vertxbus.js" todir="${dist-build}/examples/groovy/webapp/web/js"/>

<copy todir="${dist-build}/mods">
<copy todir="${dist-build}/mods" includeEmptyDirs="false">
<fileset dir="${mods-src-root}">
<include name="**/*.jar"/>
<include name="**/mod.json"/>
<include name="**/*.js"/>
<include name="**/*.rb"/>
<include name="**/*.groovy"/>
<include name="**/*"/>
</fileset>
</copy>

Expand Down
2 changes: 1 addition & 1 deletion src/examples/vertx-dev
Expand Up @@ -39,4 +39,4 @@ $DIRNAME/../../src/main/javascript
MODS_DIR=$SCRIPTDIR/../../target/dist-build/vert.x-1.0.beta6/mods

java -Djava.util.logging.config.file=$DIRNAME/../../conf/logging.properties -Djruby.home=$JRUBY_HOME \
-Dvertx.mods=$MODS_DIR -Dvertx.install=$SCRIPTDIR -cp $CLASSPATH org.vertx.java.deploy.impl.cli.VertxMgr "$@"
-Dvertx.mods=$MODS_DIR -cp $CLASSPATH org.vertx.java.deploy.impl.cli.VertxMgr "$@"
72 changes: 32 additions & 40 deletions src/main/java/org/vertx/java/core/file/impl/DefaultFileSystem.java
Expand Up @@ -26,6 +26,8 @@
import org.vertx.java.core.impl.BlockingAction;
import org.vertx.java.core.impl.Context;
import org.vertx.java.core.impl.VertxInternal;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.core.logging.impl.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -57,7 +59,9 @@
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class DefaultFileSystem implements FileSystem {


private static final Logger log = LoggerFactory.getLogger(DefaultFileSystem.class);

private final VertxInternal vertx;

public DefaultFileSystem(VertxInternal vertx) {
Expand Down Expand Up @@ -318,9 +322,8 @@ private BlockingAction<Void> copyInternal(String from, String to, AsyncResultHan
}

private BlockingAction<Void> copyInternal(String from, String to, final boolean recursive, AsyncResultHandler<Void> handler) {

final Path source = Paths.get(from);
final Path target = Paths.get(to);
final Path source = PathAdjuster.adjust(Paths.get(from));
final Path target = PathAdjuster.adjust(Paths.get(to));
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
try {
Expand Down Expand Up @@ -359,10 +362,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
}

private BlockingAction<Void> moveInternal(String from, String to, AsyncResultHandler<Void> handler) {

//TODO atomic moves - but they have different semantics, e.g. on Linux if target already exists it is overwritten
final Path source = Paths.get(from);
final Path target = Paths.get(to);
final Path source = PathAdjuster.adjust(Paths.get(from));
final Path target = PathAdjuster.adjust(Paths.get(to));
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
try {
Expand All @@ -377,8 +378,8 @@ public Void action() throws Exception {
};
}

private BlockingAction<Void> truncateInternal(final String path, final long len, AsyncResultHandler<Void> handler) {

private BlockingAction<Void> truncateInternal(String p, final long len, AsyncResultHandler<Void> handler) {
final String path = PathAdjuster.adjust(p);
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
if (len < 0) {
Expand Down Expand Up @@ -407,8 +408,7 @@ private BlockingAction<Void> chmodInternal(String path, String perms, AsyncResul
}

private BlockingAction<Void> chmodInternal(String path, String perms, String dirPerms, AsyncResultHandler<Void> handler) {

final Path target = Paths.get(path);
final Path target = PathAdjuster.adjust(Paths.get(path));
final Set<PosixFilePermission> permissions = PosixFilePermissions.fromString(perms);
final Set<PosixFilePermission> dirPermissions = dirPerms == null ? null : PosixFilePermissions.fromString(dirPerms);
return new BlockingAction<Void>(vertx, handler) {
Expand Down Expand Up @@ -448,8 +448,7 @@ private BlockingAction<FileProps> lpropsInternal(String path, AsyncResultHandler
}

private BlockingAction<FileProps> props(String path, final boolean followLinks, AsyncResultHandler<FileProps> handler) {

final Path target = Paths.get(path);
final Path target = PathAdjuster.adjust(Paths.get(path));
return new BlockingAction<FileProps>(vertx, handler) {
public FileProps action() throws Exception {
try {
Expand All @@ -476,9 +475,8 @@ private BlockingAction<Void> symlinkInternal(String link, String existing, Async
}

private BlockingAction<Void> link(String link, String existing, final boolean symbolic, AsyncResultHandler<Void> handler) {

final Path source = Paths.get(link);
final Path target = Paths.get(existing);
final Path source = PathAdjuster.adjust(Paths.get(link));
final Path target = PathAdjuster.adjust(Paths.get(existing));
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
try {
Expand All @@ -500,8 +498,7 @@ private BlockingAction<Void> unlinkInternal(String link, AsyncResultHandler<Void
}

private BlockingAction<String> readSymlinkInternal(String link, AsyncResultHandler<String> handler) {

final Path source = Paths.get(link);
final Path source = PathAdjuster.adjust(Paths.get(link));
return new BlockingAction<String>(vertx, handler) {
public String action() throws Exception {
try {
Expand All @@ -518,8 +515,7 @@ private BlockingAction<Void> deleteInternal(String path, AsyncResultHandler<Void
}

private BlockingAction<Void> deleteInternal(String path, final boolean recursive, AsyncResultHandler<Void> handler) {

final Path source = Paths.get(path);
final Path source = PathAdjuster.adjust(Paths.get(path));
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
if (recursive) {
Expand Down Expand Up @@ -564,8 +560,7 @@ private BlockingAction<Void> mkdirInternal(String path, String perms, AsyncResul
}

private BlockingAction<Void> mkdirInternal(String path, final String perms, final boolean createParents, AsyncResultHandler<Void> handler) {

final Path source = Paths.get(path);
final Path source = PathAdjuster.adjust(Paths.get(path));
final FileAttribute<?> attrs = perms == null ? null : PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(perms));
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
Expand Down Expand Up @@ -597,8 +592,8 @@ private BlockingAction<String[]> readDirInternal(String path, AsyncResultHandler
return readDirInternal(path, null, handler);
}

private BlockingAction<String[]> readDirInternal(final String path, final String filter, AsyncResultHandler<String[]> handler) {

private BlockingAction<String[]> readDirInternal(String p, final String filter, AsyncResultHandler<String[]> handler) {
final String path = PathAdjuster.adjust(p);
return new BlockingAction<String[]>(vertx, handler) {
public String[] action() throws Exception {
File file = new File(path);
Expand Down Expand Up @@ -635,23 +630,21 @@ public boolean accept(File dir, String name) {
};
}

private BlockingAction<Buffer> readFileInternal(final String path, AsyncResultHandler<Buffer> handler) {

private BlockingAction<Buffer> readFileInternal(String path, AsyncResultHandler<Buffer> handler) {
final Path target = PathAdjuster.adjust(Paths.get(path));
return new BlockingAction<Buffer>(vertx, handler) {
public Buffer action() throws Exception {
Path target = Paths.get(path);
byte[] bytes = Files.readAllBytes(target);
Buffer buff = new Buffer(bytes);
return buff;
}
};
}

private BlockingAction<Void> writeFileInternal(final String path, final Buffer data, AsyncResultHandler<Void> handler) {

private BlockingAction<Void> writeFileInternal(String path, final Buffer data, AsyncResultHandler<Void> handler) {
final Path target = PathAdjuster.adjust(Paths.get(path));
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
Path target = Paths.get(path);
Files.write(target, data.getBytes());
return null;
}
Expand All @@ -674,8 +667,9 @@ private BlockingAction<AsyncFile> openInternal(String path, String perms, boolea
return openInternal(path, perms, read, write, createNew, false, handler);
}

private BlockingAction<AsyncFile> openInternal(final String path, final String perms, final boolean read, final boolean write, final boolean createNew,
private BlockingAction<AsyncFile> openInternal(String p, final String perms, final boolean read, final boolean write, final boolean createNew,
final boolean flush, AsyncResultHandler<AsyncFile> handler) {
final String path = PathAdjuster.adjust(p);
return new BlockingAction<AsyncFile>(vertx, handler) {
public AsyncFile action() throws Exception {
return doOpen(path, perms, read, write, createNew, flush, context);
Expand All @@ -692,8 +686,8 @@ private BlockingAction<Void> createFileInternal(String path, AsyncResultHandler<
return createFileInternal(path, null, handler);
}

private BlockingAction<Void> createFileInternal(final String path, final String perms, AsyncResultHandler<Void> handler) {

private BlockingAction<Void> createFileInternal(String p, final String perms, AsyncResultHandler<Void> handler) {
final String path = PathAdjuster.adjust(p);
final FileAttribute<?> attrs = perms == null ? null : PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(perms));
return new BlockingAction<Void>(vertx, handler) {
public Void action() throws Exception {
Expand All @@ -712,21 +706,19 @@ public Void action() throws Exception {
};
}

private BlockingAction<Boolean> existsInternal(final String path, AsyncResultHandler<Boolean> handler) {

private BlockingAction<Boolean> existsInternal(String path, AsyncResultHandler<Boolean> handler) {
final File file = new File(PathAdjuster.adjust(path));
return new BlockingAction<Boolean>(vertx, handler) {
public Boolean action() throws Exception {
File file = new File(path);
return file.exists();
}
};
}

private BlockingAction<FileSystemProps> fsPropsInternal(final String path, AsyncResultHandler<FileSystemProps> handler) {

private BlockingAction<FileSystemProps> fsPropsInternal(String path, AsyncResultHandler<FileSystemProps> handler) {
final Path target = PathAdjuster.adjust(Paths.get(path));
return new BlockingAction<FileSystemProps>(vertx, handler) {
public FileSystemProps action() throws Exception {
Path target = Paths.get(path);
FileStore fs = Files.getFileStore(target);
return new FileSystemProps(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace());
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/vertx/java/core/file/impl/ModuleDir.java
@@ -0,0 +1,24 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed 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.vertx.java.core.file.impl;

/**
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public interface ModuleDir {
String get();
}
42 changes: 42 additions & 0 deletions src/main/java/org/vertx/java/core/file/impl/PathAdjuster.java
@@ -0,0 +1,42 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed 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.vertx.java.core.file.impl;

import org.vertx.java.core.impl.Context;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class PathAdjuster {

public static Path adjust(Path path) {
Path adjustment = Context.getContext().getPathAdjustment();
if (adjustment == null) {
return path;
} else {
return adjustment.resolve(path);
}
}

public static String adjust(String path) {
Path adjustment = adjust(Paths.get(path));
return adjustment.toString();
}
}
Expand Up @@ -30,6 +30,7 @@
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.vertx.java.core.Handler;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.file.impl.PathAdjuster;
import org.vertx.java.core.http.HttpServerResponse;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.core.logging.impl.LoggerFactory;
Expand Down Expand Up @@ -239,7 +240,7 @@ public DefaultHttpServerResponse sendFile(String filename) {
throw new IllegalStateException("Head already written");
}
checkWritten();
File file = new File(filename);
File file = new File(PathAdjuster.adjust(filename));
if (!file.exists()) {
sendNotFound();
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/vertx/java/core/impl/Context.java
Expand Up @@ -16,9 +16,11 @@

package org.vertx.java.core.impl;

import org.vertx.java.core.file.impl.ModuleDir;
import org.vertx.java.core.logging.Logger;
import org.vertx.java.core.logging.impl.LoggerFactory;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -32,6 +34,7 @@ public abstract class Context {
private static final ThreadLocal<Context> contextTL = new ThreadLocal<>();

private DeploymentHandle deploymentContext;
private Path pathAdjustment;

private List<Runnable> closeHooks;

Expand All @@ -51,6 +54,15 @@ public DeploymentHandle getDeploymentHandle() {
return deploymentContext;
}

public Path getPathAdjustment() {
return pathAdjustment;
}

public void setPathAdjustment(Path pathAdjustment) {
this.pathAdjustment = pathAdjustment;
}


public void reportException(Throwable t) {
if (deploymentContext != null) {
deploymentContext.reportException(t);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.vertx.java.core.SimpleHandler;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.file.impl.PathAdjuster;
import org.vertx.java.core.impl.Context;
import org.vertx.java.core.impl.VertxInternal;
import org.vertx.java.core.logging.Logger;
Expand Down Expand Up @@ -114,7 +115,7 @@ public void handle() {
}

public void sendFile(String filename) {
File f = new File(filename);
File f = new File(PathAdjuster.adjust(filename));
super.sendFile(f);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/vertx/java/deploy/Container.java
Expand Up @@ -91,7 +91,7 @@ public String deployWorkerVerticle(String main, JsonObject config, int instances
*/
public String deployWorkerVerticle(String main, JsonObject config, int instances, Handler<Void> doneHandler) {
URL[] currURLs = mgr.getDeploymentURLs();
return mgr.deploy(true, null, main, config, currURLs, instances, doneHandler);
return mgr.deploy(true, null, main, config, currURLs, instances, null, doneHandler);
}

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ public String deployVerticle(String main, JsonObject config, int instances) {
*/
public String deployVerticle(String main, JsonObject config, int instances, Handler<Void> doneHandler) {
URL[] currURLs = mgr.getDeploymentURLs();
return mgr.deploy(false, null, main, config, currURLs, instances, doneHandler);
return mgr.deploy(false, null, main, config, currURLs, instances, null, doneHandler);
}

/**
Expand Down

0 comments on commit 0f2f8bb

Please sign in to comment.