From: Mathieu Baudier Date: Wed, 13 Mar 2019 11:43:48 +0000 (+0100) Subject: More Jackrabbit repo to client dep. Remove unused and deprecated X-Git-Tag: argeo-commons-2.1.77~27 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=d6bb3d3e0643c410ecd3ca1d4d88ae412697f258 More Jackrabbit repo to client dep. Remove unused and deprecated components. --- diff --git a/dep/org.argeo.dep.cms.client/pom.xml b/dep/org.argeo.dep.cms.client/pom.xml index 7605293a3..1df3b1d0b 100644 --- a/dep/org.argeo.dep.cms.client/pom.xml +++ b/dep/org.argeo.dep.cms.client/pom.xml @@ -17,11 +17,21 @@ org.argeo.util 2.1.77-SNAPSHOT + + org.argeo.commons + org.argeo.enterprise + 2.1.77-SNAPSHOT + org.argeo.commons org.argeo.jcr 2.1.77-SNAPSHOT + + org.argeo.commons + org.argeo.core + 2.1.77-SNAPSHOT + @@ -60,6 +70,10 @@ org.argeo.tp.bouncycastle bcpkix + + org.argeo.tp.bouncycastle + bcpg + org.argeo.tp.apache org.apache.httpcomponents.httpcore @@ -121,6 +135,12 @@ javax.servlet + + + org.argeo.tp.misc + org.h2 + + org.argeo.tp.equinox @@ -253,6 +273,40 @@ org.apache.jackrabbit.jcr2spi + + + org.argeo.tp.apache.jackrabbit + org.apache.jackrabbit.data + + + org.argeo.tp.apache.jackrabbit + org.apache.jackrabbit.core + + + org.argeo.tp.apache.jackrabbit + org.apache.jackrabbit.server + + + org.argeo.tp.misc + EDU.oswego.cs.dl.util.concurrent + + + org.argeo.tp.apache.commons + org.apache.commons.fileupload + + + org.argeo.tp.apache + org.apache.tika.core + + + org.argeo.tp.apache + org.apache.tika.parsers + + + org.argeo.tp.apache + org.apache.lucene + + org.argeo.tp.misc diff --git a/dep/org.argeo.dep.cms.node/pom.xml b/dep/org.argeo.dep.cms.node/pom.xml index 83d83e76d..8e70bb829 100644 --- a/dep/org.argeo.dep.cms.node/pom.xml +++ b/dep/org.argeo.dep.cms.node/pom.xml @@ -30,11 +30,6 @@ org.argeo.cms 2.1.77-SNAPSHOT - - org.argeo.commons - org.argeo.enterprise - 2.1.77-SNAPSHOT - org.argeo.commons org.argeo.ext.jackrabbit @@ -63,10 +58,6 @@ - - org.argeo.tp.misc - org.h2 - org.argeo.tp.misc org.postgresql.jdbc42 @@ -121,39 +112,6 @@ com.vladsch.flexmark.formatter - - - org.argeo.tp.apache.jackrabbit - org.apache.jackrabbit.data - - - org.argeo.tp.apache.jackrabbit - org.apache.jackrabbit.core - - - org.argeo.tp.apache.jackrabbit - org.apache.jackrabbit.server - - - org.argeo.tp.misc - EDU.oswego.cs.dl.util.concurrent - - - org.argeo.tp.apache.commons - org.apache.commons.fileupload - - - org.argeo.tp.apache - org.apache.tika.core - - - org.argeo.tp.apache - org.apache.tika.parsers - - - org.argeo.tp.apache - org.apache.lucene - diff --git a/org.argeo.core/.classpath b/org.argeo.core/.classpath new file mode 100644 index 000000000..a7acb8257 --- /dev/null +++ b/org.argeo.core/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/org.argeo.core/.gitignore b/org.argeo.core/.gitignore new file mode 100644 index 000000000..09e3bc9b2 --- /dev/null +++ b/org.argeo.core/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/org.argeo.core/.project b/org.argeo.core/.project new file mode 100644 index 000000000..cb3127eb8 --- /dev/null +++ b/org.argeo.core/.project @@ -0,0 +1,28 @@ + + + org.argeo.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.argeo.core/.settings/org.eclipse.jdt.core.prefs b/org.argeo.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..7e2e11935 --- /dev/null +++ b/org.argeo.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,101 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullable.secondary= +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.problem.APILeak=warning +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled +org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning diff --git a/org.argeo.core/META-INF/.gitignore b/org.argeo.core/META-INF/.gitignore new file mode 100644 index 000000000..4854a41b9 --- /dev/null +++ b/org.argeo.core/META-INF/.gitignore @@ -0,0 +1 @@ +/MANIFEST.MF diff --git a/org.argeo.core/bnd.bnd b/org.argeo.core/bnd.bnd new file mode 100644 index 000000000..3ae5c176e --- /dev/null +++ b/org.argeo.core/bnd.bnd @@ -0,0 +1 @@ +Main-Class: org.argeo.sync.cli.Sync diff --git a/org.argeo.core/build.properties b/org.argeo.core/build.properties new file mode 100644 index 000000000..f3e2c2ccb --- /dev/null +++ b/org.argeo.core/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . +additional.bundles = org.apache.sshd.common,\ + org.slf4j.log4j12,\ + org.slf4j.api,\ + org.apache.sshd.core diff --git a/org.argeo.core/lib/.gitignore b/org.argeo.core/lib/.gitignore new file mode 100644 index 000000000..2142dc129 --- /dev/null +++ b/org.argeo.core/lib/.gitignore @@ -0,0 +1 @@ +/tomcat-jni-*.jar diff --git a/org.argeo.core/pom.xml b/org.argeo.core/pom.xml new file mode 100644 index 000000000..1b2ccc65a --- /dev/null +++ b/org.argeo.core/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + org.argeo.commons + argeo-commons + 2.1.77-SNAPSHOT + .. + + org.argeo.core + Commons Third Parties Utilities + + + org.argeo.commons + org.argeo.util + 2.1.77-SNAPSHOT + + + org.argeo.commons + org.argeo.jcr + 2.1.77-SNAPSHOT + + + \ No newline at end of file diff --git a/org.argeo.core/src/org/argeo/sync/SyncException.java b/org.argeo.core/src/org/argeo/sync/SyncException.java new file mode 100644 index 000000000..89bf869a2 --- /dev/null +++ b/org.argeo.core/src/org/argeo/sync/SyncException.java @@ -0,0 +1,18 @@ +package org.argeo.sync; + +/** Commons exception for sync */ +public class SyncException extends RuntimeException { + private static final long serialVersionUID = -3371314343580218538L; + + public SyncException(String message) { + super(message); + } + + public SyncException(String message, Throwable cause) { + super(message, cause); + } + + public SyncException(Object source, Object target, Throwable cause) { + super("Cannot sync from " + source + " to " + target, cause); + } +} diff --git a/org.argeo.core/src/org/argeo/sync/cli/Sync.java b/org.argeo.core/src/org/argeo/sync/cli/Sync.java new file mode 100644 index 000000000..6bb098b19 --- /dev/null +++ b/org.argeo.core/src/org/argeo/sync/cli/Sync.java @@ -0,0 +1,35 @@ +package org.argeo.sync.cli; + +import java.net.URI; +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.argeo.sync.fs.PathSync; + +public class Sync { + + public static void main(String[] args) { + Options options = new Options(); + options.addOption("r", "recursive", false, "recurse into directories"); + options.addOption(Option.builder().longOpt("progress").hasArg(false).desc("").build()); + + CommandLineParser parser = new DefaultParser(); + try { + CommandLine line = parser.parse(options, args); + List remaining = line.getArgList(); + + URI sourceUri = new URI(remaining.get(0)); + URI targetUri = new URI(remaining.get(1)); + PathSync pathSync = new PathSync(sourceUri, targetUri); + pathSync.run(); + } catch (Exception exp) { + exp.printStackTrace(); + + } + } + +} diff --git a/org.argeo.core/src/org/argeo/sync/fs/PathSync.java b/org.argeo.core/src/org/argeo/sync/fs/PathSync.java new file mode 100644 index 000000000..1dc30db65 --- /dev/null +++ b/org.argeo.core/src/org/argeo/sync/fs/PathSync.java @@ -0,0 +1,60 @@ +package org.argeo.sync.fs; + +import java.net.URI; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.spi.FileSystemProvider; +import java.time.ZonedDateTime; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.jackrabbit.fs.DavexFsProvider; +import org.argeo.sync.SyncException; +import org.argeo.util.LangUtils; + +public class PathSync implements Runnable { + private final static Log log = LogFactory.getLog(PathSync.class); + + private final URI sourceUri, targetUri; + + public PathSync(URI sourceUri, URI targetUri) { + this.sourceUri = sourceUri; + this.targetUri = targetUri; + } + + @Override + public void run() { + try { + FileSystemProvider sourceFsProvider = createFsProvider(sourceUri); + FileSystemProvider targetFsProvider = createFsProvider(targetUri); + Path sourceBasePath = sourceUri.getScheme() != null ? sourceFsProvider.getPath(sourceUri) + : Paths.get(sourceUri.getPath()); + Path targetBasePath = targetUri.getScheme() != null ? targetFsProvider.getPath(targetUri) + : Paths.get(targetUri.getPath()); + SyncFileVisitor syncFileVisitor = new SyncFileVisitor(sourceBasePath, targetBasePath); + ZonedDateTime begin = ZonedDateTime.now(); + Files.walkFileTree(sourceBasePath, syncFileVisitor); + if (log.isDebugEnabled()) + log.debug("Sync from " + sourceBasePath + " to " + targetBasePath + " took " + LangUtils.since(begin)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static FileSystemProvider createFsProvider(URI uri) { + FileSystemProvider fsProvider; + if (uri.getScheme() == null || uri.getScheme().equals("file")) + fsProvider = FileSystems.getDefault().provider(); + else if (uri.getScheme().equals("davex")) + fsProvider = new DavexFsProvider(); + else + throw new SyncException("URI scheme not supported for " + uri); + return fsProvider; + } + + static enum Arg { + to, from; + } +} diff --git a/org.argeo.core/src/org/argeo/sync/fs/SshSync.java b/org.argeo.core/src/org/argeo/sync/fs/SshSync.java new file mode 100644 index 000000000..43af45036 --- /dev/null +++ b/org.argeo.core/src/org/argeo/sync/fs/SshSync.java @@ -0,0 +1,163 @@ +package org.argeo.sync.fs; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.PublicKey; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.sshd.agent.SshAgent; +import org.apache.sshd.agent.SshAgentFactory; +import org.apache.sshd.agent.local.LocalAgentFactory; +import org.apache.sshd.agent.unix.UnixAgentFactory; +import org.apache.sshd.client.SshClient; +import org.apache.sshd.client.channel.ClientChannel; +import org.apache.sshd.client.channel.ClientChannelEvent; +import org.apache.sshd.client.config.keys.ClientIdentityLoader; +import org.apache.sshd.client.future.ConnectFuture; +import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.client.subsystem.sftp.SftpFileSystem; +import org.apache.sshd.client.subsystem.sftp.SftpFileSystemProvider; +import org.apache.sshd.common.config.keys.FilePasswordProvider; +import org.apache.sshd.common.util.io.NoCloseInputStream; +import org.apache.sshd.common.util.io.NoCloseOutputStream; + +public class SshSync { + private final static Log log = LogFactory.getLog(SshSync.class); + + public static void main(String[] args) { + + try (SshClient client = SshClient.setUpDefaultClient()) { + client.start(); + boolean osAgent = false; + SshAgentFactory agentFactory = osAgent ? new UnixAgentFactory() : new LocalAgentFactory(); + // SshAgentFactory agentFactory = new LocalAgentFactory(); + client.setAgentFactory(agentFactory); + SshAgent sshAgent = agentFactory.createClient(client); + + String login = System.getProperty("user.name"); + String host = "localhost"; + int port = 22; + + if (!osAgent) { + String keyPath = "/home/" + login + "/.ssh/id_rsa"; + System.out.print(keyPath + ": "); + Scanner s = new Scanner(System.in); + String password = s.next(); + KeyPair keyPair = ClientIdentityLoader.DEFAULT.loadClientIdentity(keyPath, + FilePasswordProvider.of(password)); + sshAgent.addIdentity(keyPair, "NO COMMENT"); + } + + List> identities = sshAgent.getIdentities(); + for (Map.Entry entry : identities) { + System.out.println(entry.getValue() + " : " + entry.getKey()); + } + + ConnectFuture connectFuture = client.connect(login, host, port); + connectFuture.await(); + ClientSession session = connectFuture.getSession(); + + try { + +// session.addPasswordIdentity(new String(password)); + session.auth().verify(1000l); + + SftpFileSystemProvider fsProvider = new SftpFileSystemProvider(client); + + SftpFileSystem fs = fsProvider.newFileSystem(session); + Path testPath = fs.getPath("/home/" + login + "/tmp"); + Files.list(testPath).forEach(System.out::println); + test(testPath); + + } finally { + client.stop(); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + static void test(Path testBase) { + try { + Path testPath = testBase.resolve("ssh-test.txt"); + Files.createFile(testPath); + log.debug("Created file " + testPath); + Files.delete(testPath); + log.debug("Deleted " + testPath); + String txt = "TEST\nTEST2\n"; + byte[] arr = txt.getBytes(); + Files.write(testPath, arr); + log.debug("Wrote " + testPath); + byte[] read = Files.readAllBytes(testPath); + log.debug("Read " + testPath); + Path testDir = testBase.resolve("testDir"); + log.debug("Resolved " + testDir); + // Copy + Files.createDirectory(testDir); + log.debug("Created directory " + testDir); + Path subsubdir = Files.createDirectories(testDir.resolve("subdir/subsubdir")); + log.debug("Created sub directories " + subsubdir); + Path copiedFile = testDir.resolve("copiedFile.txt"); + log.debug("Resolved " + copiedFile); + Path relativeCopiedFile = testDir.relativize(copiedFile); + log.debug("Relative copied file " + relativeCopiedFile); + try (OutputStream out = Files.newOutputStream(copiedFile); + InputStream in = Files.newInputStream(testPath)) { + IOUtils.copy(in, out); + } + log.debug("Copied " + testPath + " to " + copiedFile); + Files.delete(testPath); + log.debug("Deleted " + testPath); + byte[] copiedRead = Files.readAllBytes(copiedFile); + log.debug("Read " + copiedFile); + // Browse directories + DirectoryStream files = Files.newDirectoryStream(testDir); + int fileCount = 0; + Path listedFile = null; + for (Path file : files) { + fileCount++; + if (!Files.isDirectory(file)) + listedFile = file; + } + log.debug("Listed " + testDir); + // Generic attributes + Map attrs = Files.readAttributes(copiedFile, "*"); + log.debug("Read attributes of " + copiedFile + ": " + attrs.keySet()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + static void openShell(ClientSession session) { + try (ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) { + channel.setIn(new NoCloseInputStream(System.in)); + channel.setOut(new NoCloseOutputStream(System.out)); + channel.setErr(new NoCloseOutputStream(System.err)); + channel.open(); + + Set events = new HashSet<>(); + events.add(ClientChannelEvent.CLOSED); + channel.waitFor(events, 0); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + session.close(false); + } + } +} diff --git a/org.argeo.core/src/org/argeo/sync/fs/SyncFileVisitor.java b/org.argeo.core/src/org/argeo/sync/fs/SyncFileVisitor.java new file mode 100644 index 000000000..de8032004 --- /dev/null +++ b/org.argeo.core/src/org/argeo/sync/fs/SyncFileVisitor.java @@ -0,0 +1,56 @@ +package org.argeo.sync.fs; + +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** Synchronises two directory structures. */ +public class SyncFileVisitor extends SimpleFileVisitor { + private final static Log log = LogFactory.getLog(SyncFileVisitor.class); + + private final Path sourceBasePath; + private final Path targetBasePath; + + public SyncFileVisitor(Path sourceBasePath, Path targetBasePath) { + this.sourceBasePath = sourceBasePath; + this.targetBasePath = targetBasePath; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + Path targetPath = toTargetPath(dir); + Files.createDirectories(targetPath); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Path targetPath = toTargetPath(file); + try { + Files.copy(file, targetPath); + if (log.isDebugEnabled()) + log.debug("Copied " + targetPath); + } catch (Exception e) { + log.error("Cannot copy " + file + " to " + targetPath, e); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + log.error("Cannot sync " + file, exc); + return FileVisitResult.CONTINUE; + } + + private Path toTargetPath(Path sourcePath) { + Path relativePath = sourceBasePath.relativize(sourcePath); + Path targetPath = targetBasePath.resolve(relativePath.toString()); + return targetPath; + } +} diff --git a/org.argeo.enterprise/build.properties b/org.argeo.enterprise/build.properties index af03ba43b..6fa156125 100644 --- a/org.argeo.enterprise/build.properties +++ b/org.argeo.enterprise/build.properties @@ -4,5 +4,4 @@ additional.bundles = org.junit,\ org.slf4j.commons.logging,\ org.slf4j.api,\ org.slf4j.log4j12,\ - org.apache.log4j,\ - bitronix.tm + org.apache.log4j diff --git a/org.argeo.enterprise/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java b/org.argeo.enterprise/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java index 956bb2e23..748abe835 100644 --- a/org.argeo.enterprise/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java +++ b/org.argeo.enterprise/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java @@ -2,7 +2,6 @@ package org.argeo.osgi.useradmin; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -16,7 +15,6 @@ import java.util.Base64; import java.util.Dictionary; import java.util.Hashtable; import java.util.List; -import java.util.UUID; import javax.transaction.TransactionManager; @@ -27,9 +25,6 @@ import org.osgi.service.useradmin.Group; import org.osgi.service.useradmin.Role; import org.osgi.service.useradmin.User; -import bitronix.tm.BitronixTransactionManager; -import bitronix.tm.TransactionManagerServices; -import bitronix.tm.resource.ehcache.EhCacheXAResourceProducer; import junit.framework.TestCase; public class LdifUserAdminTest extends TestCase implements BasicTestConstants { @@ -45,7 +40,6 @@ public class LdifUserAdminTest extends TestCase implements BasicTestConstants { // public void testConcurrent() throws Exception { // } - @SuppressWarnings("unchecked") public void testEdition() throws Exception { User demoUser = (User) userAdmin.getRole(DEMO_USER_DN); assertNotNull(demoUser); @@ -160,13 +154,14 @@ public class LdifUserAdminTest extends TestCase implements BasicTestConstants { // Init transaction manager if (TM_SIMPLE == tmType) { tm = new SimpleTransactionManager(); - } else if (TM_BITRONIX == tmType) { - bitronix.tm.Configuration tmConf = TransactionManagerServices.getConfiguration(); - tmConf.setServerId(UUID.randomUUID().toString()); - tmConf.setLogPart1Filename(new File(tempDir.toFile(), "btm1.tlog").getAbsolutePath()); - tmConf.setLogPart2Filename(new File(tempDir.toFile(), "btm2.tlog").getAbsolutePath()); - tm = TransactionManagerServices.getTransactionManager(); } +// else if (TM_BITRONIX == tmType) { +// bitronix.tm.Configuration tmConf = TransactionManagerServices.getConfiguration(); +// tmConf.setServerId(UUID.randomUUID().toString()); +// tmConf.setLogPart1Filename(new File(tempDir.toFile(), "btm1.tlog").getAbsolutePath()); +// tmConf.setLogPart2Filename(new File(tempDir.toFile(), "btm2.tlog").getAbsolutePath()); +// tm = TransactionManagerServices.getTransactionManager(); +// } userAdmin = initUserAdmin(uri, tm); } @@ -184,15 +179,15 @@ public class LdifUserAdminTest extends TestCase implements BasicTestConstants { userAdmin = new LdifUserAdmin(props); userAdmin.init(); // JTA - if (TM_BITRONIX == tmType) - EhCacheXAResourceProducer.registerXAResource(UserDirectory.class.getName(), userAdmin.getXaResource()); +// if (TM_BITRONIX == tmType) +// EhCacheXAResourceProducer.registerXAResource(UserDirectory.class.getName(), userAdmin.getXaResource()); userAdmin.setTransactionManager(tm); return userAdmin; } private void persistAndRestart() { - if (TM_BITRONIX == tmType) - EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource()); +// if (TM_BITRONIX == tmType) +// EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource()); if (userAdmin instanceof LdifUserAdmin) ((LdifUserAdmin) userAdmin).save(); userAdmin.destroy(); @@ -201,10 +196,10 @@ public class LdifUserAdminTest extends TestCase implements BasicTestConstants { @Override protected void tearDown() throws Exception { - if (TM_BITRONIX == tmType) { - EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource()); - ((BitronixTransactionManager) tm).shutdown(); - } +// if (TM_BITRONIX == tmType) { +// EhCacheXAResourceProducer.unregisterXAResource(UserDirectory.class.getName(), userAdmin.getXaResource()); +// ((BitronixTransactionManager) tm).shutdown(); +// } if (userAdmin != null) userAdmin.destroy(); if (tempDir != null) diff --git a/org.argeo.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java b/org.argeo.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java deleted file mode 100644 index 11dc4fab0..000000000 --- a/org.argeo.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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.argeo.server.jcr; - -import java.io.InputStream; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.jackrabbit.unit.AbstractJackrabbitTestCase; -import org.argeo.jcr.JcrResourceAdapter; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; - -@Deprecated -public class JcrResourceAdapterTest extends AbstractJackrabbitTestCase { - private static SimpleDateFormat sdf = new SimpleDateFormat( - "yyyyMMdd:hhmmss.SSS"); - - private final static Log log = LogFactory - .getLog(JcrResourceAdapterTest.class); - - private JcrResourceAdapter jra; - - public void testCreate() throws Exception { - String basePath = "/test/subdir"; - jra.mkdirs(basePath); - Resource res = new ClassPathResource("org/argeo/server/jcr/dummy00.xls"); - String filePath = basePath + "/dummy.xml"; - jra.create(filePath, res.getInputStream(), "application/vnd.ms-excel"); - InputStream in = jra.retrieve(filePath); - assertTrue(IOUtils.contentEquals(res.getInputStream(), in)); - } - - public void testVersioning() throws Exception { - String basePath = "/test/versions"; - jra.mkdirs(basePath); - String filePath = basePath + "/dummy.xml"; - Resource res00 = new ClassPathResource( - "org/argeo/server/jcr/dummy00.xls"); - jra.create(filePath, res00.getInputStream(), "application/vnd.ms-excel"); - Resource res01 = new ClassPathResource( - "org/argeo/server/jcr/dummy01.xls"); - jra.update(filePath, res01.getInputStream()); - Resource res02 = new ClassPathResource( - "org/argeo/server/jcr/dummy02.xls"); - jra.update(filePath, res02.getInputStream()); - - List versions = jra.listVersions(filePath); - log.debug("Versions of " + filePath); - int count = 0; - for (Calendar version : versions) { - log.debug(" " + (count == 0 ? "base" : count - 1) + "\t" - + sdf.format(version.getTime())); - count++; - } - - assertEquals(4, versions.size()); - - InputStream in = jra.retrieve(filePath, 1); - assertTrue(IOUtils.contentEquals(res01.getInputStream(), in)); - in = jra.retrieve(filePath, 0); - assertTrue(IOUtils.contentEquals(res00.getInputStream(), in)); - in = jra.retrieve(filePath, 2); - assertTrue(IOUtils.contentEquals(res02.getInputStream(), in)); - Resource res03 = new ClassPathResource( - "org/argeo/server/jcr/dummy03.xls"); - jra.update(filePath, res03.getInputStream()); - in = jra.retrieve(filePath, 1); - assertTrue(IOUtils.contentEquals(res01.getInputStream(), in)); - } - - @Override - protected void setUp() throws Exception { - log.debug("SET UP"); - super.setUp(); - jra = new JcrResourceAdapter(); - jra.setSession(session()); - } - - @Override - protected void tearDown() throws Exception { - log.debug("TEAR DOWN"); - super.tearDown(); - } -} diff --git a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy00.xls b/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy00.xls deleted file mode 100644 index e5846fef7..000000000 Binary files a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy00.xls and /dev/null differ diff --git a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy01.xls b/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy01.xls deleted file mode 100644 index b5c6b5539..000000000 Binary files a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy01.xls and /dev/null differ diff --git a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy02.xls b/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy02.xls deleted file mode 100644 index d73bc6605..000000000 Binary files a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy02.xls and /dev/null differ diff --git a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy03.xls b/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy03.xls deleted file mode 100644 index 0759cb927..000000000 Binary files a/org.argeo.jcr/ext/test/org/argeo/server/jcr/dummy03.xls and /dev/null differ diff --git a/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java b/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java index 8fedcf521..124795000 100644 --- a/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java +++ b/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java @@ -17,6 +17,7 @@ package org.argeo.jackrabbit; import java.io.InputStreamReader; import java.io.Reader; +import java.net.URL; import javax.jcr.Session; @@ -28,7 +29,6 @@ import org.apache.jackrabbit.core.config.RepositoryConfig; import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.JcrCallback; import org.argeo.jcr.JcrUtils; -import org.springframework.core.io.Resource; /** Migrate the data in a Jackrabbit repository. */ @Deprecated @@ -39,7 +39,7 @@ public class JackrabbitDataModelMigration implements private String dataModelNodePath; private String targetVersion; - private Resource migrationCnd; + private URL migrationCnd; private JcrCallback dataModification; /** @@ -72,7 +72,7 @@ public class JackrabbitDataModelMigration implements // apply transitional CND if (migrationCnd != null) { - reader = new InputStreamReader(migrationCnd.getInputStream()); + reader = new InputStreamReader(migrationCnd.openStream()); CndImporter.registerNodeTypes(reader, session, true); session.save(); log.info("Registered migration node types from " + migrationCnd); @@ -163,7 +163,7 @@ public class JackrabbitDataModelMigration implements this.targetVersion = targetVersion; } - public void setMigrationCnd(Resource migrationCnd) { + public void setMigrationCnd(URL migrationCnd) { this.migrationCnd = migrationCnd; } diff --git a/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java b/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java deleted file mode 100644 index f7e882e7b..000000000 --- a/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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.argeo.jackrabbit; - -import java.io.File; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.RepositoryFactory; -import javax.jcr.Session; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.jackrabbit.commons.JcrUtils; -import org.apache.jackrabbit.core.RepositoryImpl; -import org.apache.jackrabbit.core.config.RepositoryConfig; -import org.apache.jackrabbit.core.config.RepositoryConfigurationParser; -import org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory; -import org.argeo.jcr.ArgeoJcrException; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.xml.sax.InputSource; - -/** - * Repository factory which can create new repositories and access remote - * Jackrabbit repositories - */ -@Deprecated -public class JackrabbitRepositoryFactory implements RepositoryFactory { - // FIXME factorize with node - /** Key for a JCR repository alias */ - public final static String JCR_REPOSITORY_ALIAS = "argeo.jcr.repository.alias"; - /** Key for a JCR repository URI */ - public final static String JCR_REPOSITORY_URI = "argeo.jcr.repository.uri"; - - private final static Log log = LogFactory - .getLog(JackrabbitRepositoryFactory.class); - - private Resource fileRepositoryConfiguration = new ClassPathResource( - "/org/argeo/jackrabbit/repository-h2.xml"); - - @SuppressWarnings({ "rawtypes" }) - public Repository getRepository(Map parameters) throws RepositoryException { - // // check if can be found by alias - // Repository repository = super.getRepository(parameters); - // if (repository != null) - // return repository; - - // check if remote - Repository repository; - String uri = null; - if (parameters.containsKey(JCR_REPOSITORY_URI)) - uri = parameters.get(JCR_REPOSITORY_URI).toString(); - else if (parameters.containsKey(JcrUtils.REPOSITORY_URI)) - uri = parameters.get(JcrUtils.REPOSITORY_URI).toString(); - - if (uri != null) { - if (uri.startsWith("http"))// http, https - repository = createRemoteRepository(uri); - else if (uri.startsWith("file"))// http, https - repository = createFileRepository(uri, parameters); - else if (uri.startsWith("vm")) { - log.warn("URI " - + uri - + " should have been managed by generic JCR repository factory"); - repository = getRepositoryByAlias(getAliasFromURI(uri)); - } else - throw new ArgeoJcrException("Unrecognized URI format " + uri); - - } - - else if (parameters.containsKey(JCR_REPOSITORY_ALIAS)) { - // Properties properties = new Properties(); - // properties.putAll(parameters); - String alias = parameters.get(JCR_REPOSITORY_ALIAS).toString(); - // publish(alias, repository, properties); - // log.info("Registered JCR repository under alias '" + alias + "' - // with properties " + properties); - repository = getRepositoryByAlias(alias); - } else - throw new ArgeoJcrException("Not enough information in " - + parameters); - - if (repository == null) - throw new ArgeoJcrException("Repository not found " + parameters); - - return repository; - } - - protected Repository getRepositoryByAlias(String alias) { - return null; - } - - protected Repository createRemoteRepository(String uri) - throws RepositoryException { - Map params = new HashMap(); - params.put(JcrUtils.REPOSITORY_URI, uri); - Repository repository = new Jcr2davRepositoryFactory() - .getRepository(params); - if (repository == null) - throw new ArgeoJcrException("Remote Davex repository " + uri - + " not found"); - log.info("Initialized remote Jackrabbit repository from uri " + uri); - return repository; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - protected Repository createFileRepository(final String uri, Map parameters) - throws RepositoryException { - InputStream configurationIn = null; - try { - Properties vars = new Properties(); - vars.putAll(parameters); - String dirPath = uri.substring("file:".length()); - File homeDir = new File(dirPath); - if (homeDir.exists() && !homeDir.isDirectory()) - throw new ArgeoJcrException("Repository home " + dirPath - + " is not a directory"); - if (!homeDir.exists()) - homeDir.mkdirs(); - configurationIn = fileRepositoryConfiguration.getInputStream(); - vars.put(RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE, - homeDir.getCanonicalPath()); - RepositoryConfig repositoryConfig = RepositoryConfig.create( - new InputSource(configurationIn), vars); - - // TransientRepository repository = new - // TransientRepository(repositoryConfig); - final RepositoryImpl repository = RepositoryImpl - .create(repositoryConfig); - Session session = repository.login(); - // FIXME make it generic - org.argeo.jcr.JcrUtils.addPrivilege(session, "/", "ROLE_ADMIN", - "jcr:all"); - org.argeo.jcr.JcrUtils.logoutQuietly(session); - Runtime.getRuntime().addShutdownHook( - new Thread("Clean JCR repository " + uri) { - public void run() { - repository.shutdown(); - log.info("Destroyed repository " + uri); - } - }); - log.info("Initialized file Jackrabbit repository from uri " + uri); - return repository; - } catch (Exception e) { - throw new ArgeoJcrException("Cannot create repository " + uri, e); - } finally { - IOUtils.closeQuietly(configurationIn); - } - } - - protected String getAliasFromURI(String uri) { - try { - URI uriObj = new URI(uri); - String alias = uriObj.getPath(); - if (alias.charAt(0) == '/') - alias = alias.substring(1); - if (alias.charAt(alias.length() - 1) == '/') - alias = alias.substring(0, alias.length() - 1); - return alias; - } catch (URISyntaxException e) { - throw new ArgeoJcrException("Cannot interpret URI " + uri, e); - } - } - - /** - * Called after the repository has been initialised. Does nothing by - * default. - */ - @SuppressWarnings("rawtypes") - protected void postInitialization(Repository repository, Map parameters) { - - } - - public void setFileRepositoryConfiguration( - Resource fileRepositoryConfiguration) { - this.fileRepositoryConfiguration = fileRepositoryConfiguration; - } - -} diff --git a/org.argeo.jcr/src/org/argeo/jcr/JcrResourceAdapter.java b/org.argeo.jcr/src/org/argeo/jcr/JcrResourceAdapter.java deleted file mode 100644 index be7bf4959..000000000 --- a/org.argeo.jcr/src/org/argeo/jcr/JcrResourceAdapter.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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.argeo.jcr; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -import javax.jcr.Binary; -import javax.jcr.Node; -import javax.jcr.Property; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.nodetype.NodeType; -import javax.jcr.version.Version; -import javax.jcr.version.VersionHistory; -import javax.jcr.version.VersionIterator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Bridge Spring resources and JCR folder / files semantics (nt:folder / - * nt:file), supporting versioning as well. - */ -@Deprecated -public class JcrResourceAdapter { - private final static Log log = LogFactory.getLog(JcrResourceAdapter.class); - - private Session session; - - private Boolean versioning = true; - private String defaultEncoding = "UTF-8"; - - // private String restoreBase = "/.restore"; - - public JcrResourceAdapter() { - } - - public JcrResourceAdapter(Session session) { - this.session = session; - } - - public void mkdirs(String path) { - JcrUtils.mkdirs(session(), path, NodeType.NT_FOLDER, - NodeType.NT_FOLDER, versioning); - } - - public void create(String path, InputStream in, String mimeType) { - try { - if (session().itemExists(path)) { - throw new ArgeoJcrException("Node " + path + " already exists."); - } - - int index = path.lastIndexOf('/'); - String parentPath = path.substring(0, index); - if (parentPath.equals("")) - parentPath = "/"; - String fileName = path.substring(index + 1); - if (!session().itemExists(parentPath)) - throw new ArgeoJcrException("Parent folder of node " + path - + " does not exist: " + parentPath); - - Node folderNode = (Node) session().getItem(parentPath); - Node fileNode = folderNode.addNode(fileName, "nt:file"); - - Node contentNode = fileNode.addNode(Property.JCR_CONTENT, - "nt:resource"); - if (mimeType != null) - contentNode.setProperty(Property.JCR_MIMETYPE, mimeType); - contentNode.setProperty(Property.JCR_ENCODING, defaultEncoding); - Binary binary = session().getValueFactory().createBinary(in); - contentNode.setProperty(Property.JCR_DATA, binary); - JcrUtils.closeQuietly(binary); - Calendar lastModified = Calendar.getInstance(); - // lastModified.setTimeInMillis(file.lastModified()); - contentNode.setProperty(Property.JCR_LAST_MODIFIED, lastModified); - // resNode.addMixin("mix:referenceable"); - - if (versioning) - fileNode.addMixin("mix:versionable"); - - session().save(); - - if (versioning) - session().getWorkspace().getVersionManager() - .checkin(fileNode.getPath()); - - if (log.isDebugEnabled()) - log.debug("Created " + path); - } catch (Exception e) { - throw new ArgeoJcrException("Cannot create node for " + path, e); - } - - } - - public void update(String path, InputStream in) { - try { - - if (!session().itemExists(path)) { - String type = null; - // FIXME: using javax.activation leads to conflict between Java - // 1.5 and 1.6 (since javax.activation was included in Java 1.6) - // String type = new MimetypesFileTypeMap() - // .getContentType(FilenameUtils.getName(path)); - create(path, in, type); - return; - } - - Node fileNode = (Node) session().getItem(path); - Node contentNode = fileNode.getNode(Property.JCR_CONTENT); - if (versioning) - session().getWorkspace().getVersionManager() - .checkout(fileNode.getPath()); - Binary binary = session().getValueFactory().createBinary(in); - contentNode.setProperty(Property.JCR_DATA, binary); - JcrUtils.closeQuietly(binary); - Calendar lastModified = Calendar.getInstance(); - // lastModified.setTimeInMillis(file.lastModified()); - contentNode.setProperty(Property.JCR_LAST_MODIFIED, lastModified); - - session().save(); - if (versioning) - session().getWorkspace().getVersionManager() - .checkin(fileNode.getPath()); - - if (log.isDebugEnabled()) - log.debug("Updated " + path); - } catch (Exception e) { - throw new ArgeoJcrException("Cannot update node " + path, e); - } - } - - public List listVersions(String path) { - if (!versioning) - throw new ArgeoJcrException("Versioning is not activated"); - - try { - List versions = new ArrayList(); - Node fileNode = (Node) session().getItem(path); - VersionHistory history = session().getWorkspace() - .getVersionManager().getVersionHistory(fileNode.getPath()); - for (VersionIterator it = history.getAllVersions(); it.hasNext();) { - Version version = (Version) it.next(); - versions.add(version.getCreated()); - if (log.isTraceEnabled()) { - log.debug(version); - // debug(version); - } - } - return versions; - } catch (Exception e) { - throw new ArgeoJcrException("Cannot list version of node " + path, e); - } - } - - public InputStream retrieve(String path) { - try { - Node node = (Node) session().getItem( - path + "/" + Property.JCR_CONTENT); - Property property = node.getProperty(Property.JCR_DATA); - return property.getBinary().getStream(); - } catch (Exception e) { - throw new ArgeoJcrException("Cannot retrieve " + path, e); - } - } - - public synchronized InputStream retrieve(String path, Integer revision) { - if (!versioning) - throw new ArgeoJcrException("Versioning is not activated"); - - try { - Node fileNode = (Node) session().getItem(path); - VersionHistory history = session().getWorkspace() - .getVersionManager().getVersionHistory(fileNode.getPath()); - int count = 0; - Version version = null; - for (VersionIterator it = history.getAllVersions(); it.hasNext();) { - version = (Version) it.next(); - if (count == revision + 1) { - InputStream in = fromVersion(version); - if (log.isDebugEnabled()) - log.debug("Retrieved " + path + " at revision " - + revision); - return in; - } - count++; - } - } catch (Exception e) { - throw new ArgeoJcrException("Cannot retrieve version " + revision - + " of " + path, e); - } - - throw new ArgeoJcrException("Version " + revision - + " does not exist for node " + path); - } - - protected InputStream fromVersion(Version version) - throws RepositoryException { - Node frozenNode = version.getNode("jcr:frozenNode"); - InputStream in = frozenNode.getNode(Property.JCR_CONTENT) - .getProperty(Property.JCR_DATA).getBinary().getStream(); - return in; - } - - protected Session session() { - return session; - } - - public void setVersioning(Boolean versioning) { - this.versioning = versioning; - } - - public void setDefaultEncoding(String defaultEncoding) { - this.defaultEncoding = defaultEncoding; - } - - protected String fill(Integer number) { - int size = 4; - String str = number.toString(); - for (int i = str.length(); i < size; i++) { - str = "0" + str; - } - return str; - } - - public void setSession(Session session) { - this.session = session; - } - -} diff --git a/org.argeo.jcr/src/org/argeo/jcr/spring/ThreadBoundSession.java b/org.argeo.jcr/src/org/argeo/jcr/spring/ThreadBoundSession.java deleted file mode 100644 index 35f021555..000000000 --- a/org.argeo.jcr/src/org/argeo/jcr/spring/ThreadBoundSession.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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.argeo.jcr.spring; - -import org.argeo.jcr.ThreadBoundJcrSessionFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; - -@SuppressWarnings("rawtypes") -@Deprecated -public class ThreadBoundSession extends ThreadBoundJcrSessionFactory implements FactoryBean, InitializingBean, DisposableBean{ - public void afterPropertiesSet() throws Exception { - init(); - } - - public void destroy() throws Exception { - dispose(); - } - -} diff --git a/org.argeo.sync/.classpath b/org.argeo.sync/.classpath deleted file mode 100644 index a7acb8257..000000000 --- a/org.argeo.sync/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/org.argeo.sync/.gitignore b/org.argeo.sync/.gitignore deleted file mode 100644 index 09e3bc9b2..000000000 --- a/org.argeo.sync/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/bin/ -/target/ diff --git a/org.argeo.sync/.project b/org.argeo.sync/.project deleted file mode 100644 index 38af86992..000000000 --- a/org.argeo.sync/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.sync - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/org.argeo.sync/.settings/org.eclipse.jdt.core.prefs b/org.argeo.sync/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7e2e11935..000000000 --- a/org.argeo.sync/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,101 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled -org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore -org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull -org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= -org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable -org.eclipse.jdt.core.compiler.annotation.nullable.secondary= -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled -org.eclipse.jdt.core.compiler.problem.APILeak=warning -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning -org.eclipse.jdt.core.compiler.problem.deadCode=warning -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning -org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore -org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning -org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning -org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning -org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning -org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning -org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning -org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled -org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled -org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedImport=warning -org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -org.eclipse.jdt.core.compiler.problem.unusedLocal=warning -org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning diff --git a/org.argeo.sync/META-INF/.gitignore b/org.argeo.sync/META-INF/.gitignore deleted file mode 100644 index 4854a41b9..000000000 --- a/org.argeo.sync/META-INF/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/MANIFEST.MF diff --git a/org.argeo.sync/bnd.bnd b/org.argeo.sync/bnd.bnd deleted file mode 100644 index 3ae5c176e..000000000 --- a/org.argeo.sync/bnd.bnd +++ /dev/null @@ -1 +0,0 @@ -Main-Class: org.argeo.sync.cli.Sync diff --git a/org.argeo.sync/build.properties b/org.argeo.sync/build.properties deleted file mode 100644 index f3e2c2ccb..000000000 --- a/org.argeo.sync/build.properties +++ /dev/null @@ -1,8 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . -additional.bundles = org.apache.sshd.common,\ - org.slf4j.log4j12,\ - org.slf4j.api,\ - org.apache.sshd.core diff --git a/org.argeo.sync/lib/.gitignore b/org.argeo.sync/lib/.gitignore deleted file mode 100644 index 2142dc129..000000000 --- a/org.argeo.sync/lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/tomcat-jni-*.jar diff --git a/org.argeo.sync/pom.xml b/org.argeo.sync/pom.xml deleted file mode 100644 index 4e07d4334..000000000 --- a/org.argeo.sync/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - 4.0.0 - - org.argeo.commons - argeo-commons - 2.1.77-SNAPSHOT - .. - - org.argeo.sync - Commons Sync Utility - - - org.argeo.commons - org.argeo.util - 2.1.77-SNAPSHOT - - - org.argeo.commons - org.argeo.jcr - 2.1.77-SNAPSHOT - - - \ No newline at end of file diff --git a/org.argeo.sync/src/org/argeo/sync/SyncException.java b/org.argeo.sync/src/org/argeo/sync/SyncException.java deleted file mode 100644 index 89bf869a2..000000000 --- a/org.argeo.sync/src/org/argeo/sync/SyncException.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.argeo.sync; - -/** Commons exception for sync */ -public class SyncException extends RuntimeException { - private static final long serialVersionUID = -3371314343580218538L; - - public SyncException(String message) { - super(message); - } - - public SyncException(String message, Throwable cause) { - super(message, cause); - } - - public SyncException(Object source, Object target, Throwable cause) { - super("Cannot sync from " + source + " to " + target, cause); - } -} diff --git a/org.argeo.sync/src/org/argeo/sync/cli/Sync.java b/org.argeo.sync/src/org/argeo/sync/cli/Sync.java deleted file mode 100644 index 6bb098b19..000000000 --- a/org.argeo.sync/src/org/argeo/sync/cli/Sync.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.argeo.sync.cli; - -import java.net.URI; -import java.util.List; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.argeo.sync.fs.PathSync; - -public class Sync { - - public static void main(String[] args) { - Options options = new Options(); - options.addOption("r", "recursive", false, "recurse into directories"); - options.addOption(Option.builder().longOpt("progress").hasArg(false).desc("").build()); - - CommandLineParser parser = new DefaultParser(); - try { - CommandLine line = parser.parse(options, args); - List remaining = line.getArgList(); - - URI sourceUri = new URI(remaining.get(0)); - URI targetUri = new URI(remaining.get(1)); - PathSync pathSync = new PathSync(sourceUri, targetUri); - pathSync.run(); - } catch (Exception exp) { - exp.printStackTrace(); - - } - } - -} diff --git a/org.argeo.sync/src/org/argeo/sync/fs/PathSync.java b/org.argeo.sync/src/org/argeo/sync/fs/PathSync.java deleted file mode 100644 index 1dc30db65..000000000 --- a/org.argeo.sync/src/org/argeo/sync/fs/PathSync.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.argeo.sync.fs; - -import java.net.URI; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.spi.FileSystemProvider; -import java.time.ZonedDateTime; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.jackrabbit.fs.DavexFsProvider; -import org.argeo.sync.SyncException; -import org.argeo.util.LangUtils; - -public class PathSync implements Runnable { - private final static Log log = LogFactory.getLog(PathSync.class); - - private final URI sourceUri, targetUri; - - public PathSync(URI sourceUri, URI targetUri) { - this.sourceUri = sourceUri; - this.targetUri = targetUri; - } - - @Override - public void run() { - try { - FileSystemProvider sourceFsProvider = createFsProvider(sourceUri); - FileSystemProvider targetFsProvider = createFsProvider(targetUri); - Path sourceBasePath = sourceUri.getScheme() != null ? sourceFsProvider.getPath(sourceUri) - : Paths.get(sourceUri.getPath()); - Path targetBasePath = targetUri.getScheme() != null ? targetFsProvider.getPath(targetUri) - : Paths.get(targetUri.getPath()); - SyncFileVisitor syncFileVisitor = new SyncFileVisitor(sourceBasePath, targetBasePath); - ZonedDateTime begin = ZonedDateTime.now(); - Files.walkFileTree(sourceBasePath, syncFileVisitor); - if (log.isDebugEnabled()) - log.debug("Sync from " + sourceBasePath + " to " + targetBasePath + " took " + LangUtils.since(begin)); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static FileSystemProvider createFsProvider(URI uri) { - FileSystemProvider fsProvider; - if (uri.getScheme() == null || uri.getScheme().equals("file")) - fsProvider = FileSystems.getDefault().provider(); - else if (uri.getScheme().equals("davex")) - fsProvider = new DavexFsProvider(); - else - throw new SyncException("URI scheme not supported for " + uri); - return fsProvider; - } - - static enum Arg { - to, from; - } -} diff --git a/org.argeo.sync/src/org/argeo/sync/fs/SshSync.java b/org.argeo.sync/src/org/argeo/sync/fs/SshSync.java deleted file mode 100644 index e89ba85dc..000000000 --- a/org.argeo.sync/src/org/argeo/sync/fs/SshSync.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.argeo.sync.fs; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.PublicKey; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.sshd.agent.SshAgent; -import org.apache.sshd.agent.unix.UnixAgentFactory; -import org.apache.sshd.client.SshClient; -import org.apache.sshd.client.channel.ClientChannel; -import org.apache.sshd.client.channel.ClientChannelEvent; -import org.apache.sshd.client.future.ConnectFuture; -import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.client.subsystem.sftp.SftpFileSystem; -import org.apache.sshd.client.subsystem.sftp.SftpFileSystemProvider; -import org.apache.sshd.common.util.io.NoCloseInputStream; -import org.apache.sshd.common.util.io.NoCloseOutputStream; - -public class SshSync { - private final static Log log = LogFactory.getLog(SshSync.class); - - public static void main(String[] args) { - - - try (SshClient client = SshClient.setUpDefaultClient()) { - client.start(); - - UnixAgentFactory agentFactory = new UnixAgentFactory(); - client.setAgentFactory(agentFactory); -// SshAgent sshAgent = agentFactory.createClient(client); -// List> identities = sshAgent.getIdentities(); -// for (Map.Entry entry : identities) { -// System.out.println(entry.getValue() + " : " + entry.getKey()); -// } - - - String login = System.getProperty("user.name"); -// Scanner s = new Scanner(System.in); -// String password = s.next(); - String host = "localhost"; - int port = 22; - -// SimpleClient simpleClient= AbstractSimpleClientSessionCreator.wrap(client, null); -// simpleClient.sessionLogin(host, login, password); - - ConnectFuture connectFuture = client.connect(login, host, port); - connectFuture.await(); - ClientSession session = connectFuture.getSession(); - - try { - -// session.addPasswordIdentity(new String(password)); - session.auth().verify(1000l); - - SftpFileSystemProvider fsProvider = new SftpFileSystemProvider(client); - - SftpFileSystem fs = fsProvider.newFileSystem(session); - Path testPath = fs.getPath("/home/" + login + "/tmp"); - Files.list(testPath).forEach(System.out::println); - test(testPath); - - } finally { - client.stop(); - } - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - static void test(Path testBase) { - try { - Path testPath = testBase.resolve("ssh-test.txt"); - Files.createFile(testPath); - log.debug("Created file " + testPath); - Files.delete(testPath); - log.debug("Deleted " + testPath); - String txt = "TEST\nTEST2\n"; - byte[] arr = txt.getBytes(); - Files.write(testPath, arr); - log.debug("Wrote " + testPath); - byte[] read = Files.readAllBytes(testPath); - log.debug("Read " + testPath); - Path testDir = testBase.resolve("testDir"); - log.debug("Resolved " + testDir); - // Copy - Files.createDirectory(testDir); - log.debug("Created directory " + testDir); - Path subsubdir = Files.createDirectories(testDir.resolve("subdir/subsubdir")); - log.debug("Created sub directories " + subsubdir); - Path copiedFile = testDir.resolve("copiedFile.txt"); - log.debug("Resolved " + copiedFile); - Path relativeCopiedFile = testDir.relativize(copiedFile); - log.debug("Relative copied file " + relativeCopiedFile); - try (OutputStream out = Files.newOutputStream(copiedFile); - InputStream in = Files.newInputStream(testPath)) { - IOUtils.copy(in, out); - } - log.debug("Copied " + testPath + " to " + copiedFile); - Files.delete(testPath); - log.debug("Deleted " + testPath); - byte[] copiedRead = Files.readAllBytes(copiedFile); - log.debug("Read " + copiedFile); - // Browse directories - DirectoryStream files = Files.newDirectoryStream(testDir); - int fileCount = 0; - Path listedFile = null; - for (Path file : files) { - fileCount++; - if (!Files.isDirectory(file)) - listedFile = file; - } - log.debug("Listed " + testDir); - // Generic attributes - Map attrs = Files.readAttributes(copiedFile, "*"); - log.debug("Read attributes of " + copiedFile + ": " + attrs.keySet()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - static void openShell(ClientSession session) { - try (ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) { - channel.setIn(new NoCloseInputStream(System.in)); - channel.setOut(new NoCloseOutputStream(System.out)); - channel.setErr(new NoCloseOutputStream(System.err)); - channel.open(); - - Set events = new HashSet<>(); - events.add(ClientChannelEvent.CLOSED); - channel.waitFor(events, 0); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } finally { - session.close(false); - } - } -} diff --git a/org.argeo.sync/src/org/argeo/sync/fs/SyncFileVisitor.java b/org.argeo.sync/src/org/argeo/sync/fs/SyncFileVisitor.java deleted file mode 100644 index de8032004..000000000 --- a/org.argeo.sync/src/org/argeo/sync/fs/SyncFileVisitor.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.argeo.sync.fs; - -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** Synchronises two directory structures. */ -public class SyncFileVisitor extends SimpleFileVisitor { - private final static Log log = LogFactory.getLog(SyncFileVisitor.class); - - private final Path sourceBasePath; - private final Path targetBasePath; - - public SyncFileVisitor(Path sourceBasePath, Path targetBasePath) { - this.sourceBasePath = sourceBasePath; - this.targetBasePath = targetBasePath; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - Path targetPath = toTargetPath(dir); - Files.createDirectories(targetPath); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Path targetPath = toTargetPath(file); - try { - Files.copy(file, targetPath); - if (log.isDebugEnabled()) - log.debug("Copied " + targetPath); - } catch (Exception e) { - log.error("Cannot copy " + file + " to " + targetPath, e); - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { - log.error("Cannot sync " + file, exc); - return FileVisitResult.CONTINUE; - } - - private Path toTargetPath(Path sourcePath) { - Path relativePath = sourceBasePath.relativize(sourcePath); - Path targetPath = targetBasePath.resolve(relativePath.toString()); - return targetPath; - } -} diff --git a/pom.xml b/pom.xml index 4efd8d8fc..1c9976a63 100644 --- a/pom.xml +++ b/pom.xml @@ -22,8 +22,8 @@ org.argeo.util org.argeo.enterprise org.argeo.jcr - org.argeo.sync org.argeo.osgi.boot + org.argeo.core org.argeo.eclipse.ui org.argeo.eclipse.ui.rap