Skip to content

Commit

Permalink
Merge pull request #134 from xebialabs/no-guava
Browse files Browse the repository at this point in the history
Remove compile time dependency on Guava (Fixes #134)
  • Loading branch information
hierynomus committed Nov 3, 2014
2 parents d9ece92 + 77b4c5b commit bf82f4f
Show file tree
Hide file tree
Showing 35 changed files with 241 additions and 206 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ configurations {

dependencies {
// General dependencies
compile 'com.google.guava:guava:16.0.1'
compile 'nl.javadude.scannit:scannit:1.2.1'
compile 'org.slf4j:slf4j-api:1.6.3'
compile 'org.slf4j:jcl-over-slf4j:1.6.3'
Expand Down Expand Up @@ -88,6 +87,8 @@ dependencies {
testCompile 'org.mockito:mockito-core:1.8.5'
testCompile 'org.testng:testng:5.14.10'
testCompile 'nl.javadude.assumeng:assumeng:1.2.2'
testCompile 'com.google.guava:guava:16.0.1'


testRuntime 'ch.qos.logback:logback-classic:1.0.6'
testRuntime('org.uncommons:reportng:1.1.2') {
Expand All @@ -113,8 +114,8 @@ task itest(type: Test) {
}

includes = ['**/*Itest.*', '**/LocalConnectionTest.*']
testResultsDir = file("${buildDir}/itest-results")
testReportDir = file("${buildDir}/reports/itests")
reports.junitXml.destination = file("${buildDir}/itest-results")
reports.html.destination = file("${buildDir}/reports/itests")

maxHeapSize = "512m"
copyProjectPropertyToSystemProperty(project, systemProperties, 'itests')
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-bin.zip
22 changes: 10 additions & 12 deletions src/main/java/com/xebialabs/overthere/CmdLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Function;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.xebialabs.overthere.util.OverthereUtils.checkNotNull;
import static com.xebialabs.overthere.util.OverthereUtils.checkState;
import static com.xebialabs.overthere.CmdLineArgument.arg;
import static com.xebialabs.overthere.CmdLineArgument.nested;
import static com.xebialabs.overthere.CmdLineArgument.password;
Expand All @@ -44,7 +42,7 @@
@SuppressWarnings("serial")
public class CmdLine implements Serializable {

List<CmdLineArgument> arguments = newArrayList();
List<CmdLineArgument> arguments = new ArrayList<CmdLineArgument>();

/**
* Adds {@link CmdLineArgument#arg(String) a regular argument} to the command line.
Expand Down Expand Up @@ -154,12 +152,12 @@ public List<CmdLineArgument> getArguments() {
*/
public String[] toCommandArray(final OperatingSystemFamily os, final boolean forLogging) {
checkState(arguments.size() > 0, "Cannot encode empty command line");
return transform(arguments, new Function<CmdLineArgument, String>() {
@Override
public String apply(CmdLineArgument from) {
return from.toString(os, forLogging);
}
}).toArray(new String[arguments.size()]);
String[] args = new String[arguments.size()];
for (int i = 0; i < arguments.size(); i++) {
args[i] = arguments.get(i).toString(os, forLogging);

}
return args;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xebialabs/overthere/CmdLineArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import java.io.Serializable;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.xebialabs.overthere.util.OverthereUtils.checkNotNull;
import static com.xebialabs.overthere.OperatingSystemFamily.UNIX;

/**
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/xebialabs/overthere/ConnectionOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@
*/
package com.xebialabs.overthere;

import java.util.Map;
import java.util.Set;
import java.util.*;

import com.google.common.collect.ImmutableSet;

import static com.google.common.collect.Maps.newHashMap;
import static com.xebialabs.overthere.ssh.SshConnectionBuilder.PASSPHRASE;

/**
Expand Down Expand Up @@ -172,20 +168,28 @@ public class ConnectionOptions {

private final Map<String, Object> options;

private static final ImmutableSet<String> filteredKeys = ImmutableSet.of(PASSWORD, PASSPHRASE);
private static final Set<String> filteredKeys = getFilteredKeys();

private static Set<String> getFilteredKeys() {
HashSet<String> strings = new HashSet<String>();
strings.add(PASSWORD);
strings.add(PASSPHRASE);
return Collections.unmodifiableSet(strings);
}

/**
* Creates an empty options object.
*/
public ConnectionOptions() {
options = newHashMap();
options = new HashMap<String, Object>();
}

/**
* Creates a copy of an existing options object.
*/
public ConnectionOptions(ConnectionOptions options) {
this.options = newHashMap(options.options);
this();
this.options.putAll(options.options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
*/
package com.xebialabs.overthere.cifs;

import java.util.Collections;
import java.util.Map;
import com.google.common.collect.ImmutableMap;

import com.xebialabs.overthere.ConnectionOptions;
import com.xebialabs.overthere.OverthereConnection;
Expand Down Expand Up @@ -88,7 +88,7 @@ public class CifsConnectionBuilder implements OverthereConnectionBuilder {
/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_pathShareMappings">the online documentation</a>
*/
public static final Map<String, String> PATH_SHARE_MAPPINGS_DEFAULT = ImmutableMap.of();
public static final Map<String, String> PATH_SHARE_MAPPINGS_DEFAULT = Collections.emptyMap();

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmEnableHttps">the online documentation</a>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/xebialabs/overthere/cifs/CifsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,7 +38,6 @@
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

import static com.google.common.collect.Lists.newArrayList;
import static java.lang.String.format;

class CifsFile extends BaseOverthereFile<CifsConnection> {
Expand Down Expand Up @@ -177,7 +177,7 @@ public List<OverthereFile> listFiles() throws RuntimeIOException {

try {
upgradeToDirectorySmbFile();
List<OverthereFile> files = newArrayList();
List<OverthereFile> files = new ArrayList<OverthereFile>();
for (String name : smbFile.list()) {
files.add(getFile(name));
}
Expand Down
53 changes: 27 additions & 26 deletions src/main/java/com/xebialabs/overthere/cifs/PathMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@
*/
package com.xebialabs.overthere.cifs;

import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.regex.Pattern;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables;

import static com.xebialabs.overthere.util.OverthereUtils.checkArgument;
import static java.lang.String.format;
import static java.util.regex.Pattern.quote;

Expand All @@ -43,19 +38,24 @@ class PathMapper {
private final SortedMap<String, String> sharesForPaths;
private final Map<String, String> pathsForShares;

@VisibleForTesting
PathMapper(final Map<String, String> mappings) {
// longest first, so reverse lexicographical order
ImmutableSortedMap.Builder<String, String> sharesForPath = ImmutableSortedMap.reverseOrder();
ImmutableMap.Builder<String, String> pathsForShare = ImmutableMap.builder();
SortedMap<String, String> sharesForPath = new TreeMap<String, String>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o2.compareTo(o1);
}
});
Map<String, String> pathsForShare = new HashMap<String, String>();

for (Entry<String, String> mapping : mappings.entrySet()) {
String pathPrefixToMatch = mapping.getKey();
String shareForPathPrefix = mapping.getValue();
sharesForPath.put(pathPrefixToMatch.toLowerCase(), shareForPathPrefix);
pathsForShare.put(shareForPathPrefix.toLowerCase(), pathPrefixToMatch);
checkArgument(sharesForPath.put(pathPrefixToMatch.toLowerCase(), shareForPathPrefix) == null, "path prefix is not unique in mapping %s -> %s", pathPrefixToMatch, shareForPathPrefix);
checkArgument(pathsForShare.put(shareForPathPrefix.toLowerCase(), pathPrefixToMatch) == null, "share is not unique in mapping %s -> %s", shareForPathPrefix, pathPrefixToMatch);
}
this.sharesForPaths = sharesForPath.build();
this.pathsForShares = pathsForShare.build();
this.sharesForPaths = Collections.unmodifiableSortedMap(sharesForPath);
this.pathsForShares = Collections.unmodifiableMap(pathsForShare);
}

/**
Expand All @@ -67,16 +67,16 @@ class PathMapper {
* @param path the local path to convert
* @return the remotely accessible path (using shares) at which the local path can be accessed using SMB
*/
@VisibleForTesting
String toSharedPath(String path) {
final String lowerCasePath = path.toLowerCase();
// assumes correct format drive: or drive:\path
String mappedPathPrefix = Iterables.find(sharesForPaths.keySet(), new Predicate<String>() {
@Override
public boolean apply(String input) {
return lowerCasePath.startsWith(input);
String mappedPathPrefix = null;
for (String s : sharesForPaths.keySet()) {
if (lowerCasePath.startsWith(s)) {
mappedPathPrefix = s;
break;
}
}, null);
}
// the share + the remainder of the path if found, otherwise the path with ':' replaced by '$'
return ((mappedPathPrefix != null) ? sharesForPaths.get(mappedPathPrefix) + path.substring(mappedPathPrefix.length()) : path.substring(0, 1)
+ ADMIN_SHARE_DESIGNATOR
Expand All @@ -87,16 +87,17 @@ public boolean apply(String input) {
* @param path the remotely accessible path to convert (minus the host name, i.e. beginning with the share)
* @return the local path (using drive letters) corresponding to the path that is remotely accessible using SMB
*/
@VisibleForTesting
String toLocalPath(String path) {
final String lowerCasePath = path.toLowerCase();
// assumes correct format share or share\path
String mappedShare = Iterables.find(pathsForShares.keySet(), new Predicate<String>() {
@Override
public boolean apply(String input) {
return lowerCasePath.startsWith(input);
String mappedShare = null;
for (String s : pathsForShares.keySet()) {
if (lowerCasePath.startsWith(s)) {
mappedShare = s;
break;
}
}, null);
}

if (mappedShare != null) {
return pathsForShares.get(mappedShare) + path.substring(mappedShare.length());
} else if ((path.length() >= 2) && ADMIN_SHARE_PATTERN.matcher(path.substring(0, 2)).matches()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import com.xebialabs.overthere.cifs.CifsConnection;
import com.xebialabs.overthere.spi.AddressPortMapper;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.xebialabs.overthere.util.OverthereUtils.checkArgument;
import static com.xebialabs.overthere.util.OverthereUtils.checkNotNull;
import static com.xebialabs.overthere.OperatingSystemFamily.WINDOWS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CIFS_PROTOCOL;
import static com.xebialabs.overthere.util.OverthereUtils.closeQuietly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import com.xebialabs.overthere.cifs.WinrmHttpsHostnameVerificationStrategy;
import com.xebialabs.overthere.spi.AddressPortMapper;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.xebialabs.overthere.util.OverthereUtils.checkArgument;
import static com.xebialabs.overthere.util.OverthereUtils.checkNotNull;
import static com.xebialabs.overthere.OperatingSystemFamily.WINDOWS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CIFS_PROTOCOL;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_CONTEXT_DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@
*/
package com.xebialabs.overthere.cifs.winrm.soap;

import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;

/**
*/
public enum OptionSet {

OPEN_SHELL(Lists.newArrayList(new KeyValuePair("WINRS_NOPROFILE", "FALSE"), new KeyValuePair("WINRS_CODEPAGE", "437"))),
RUN_COMMAND(Lists.newArrayList(new KeyValuePair("WINRS_CONSOLEMODE_STDIN", "TRUE")));
OPEN_SHELL(new KeyValuePair("WINRS_NOPROFILE", "FALSE"), new KeyValuePair("WINRS_CODEPAGE", "437")),
RUN_COMMAND(new KeyValuePair("WINRS_CONSOLEMODE_STDIN", "TRUE"));

private final List<KeyValuePair> keyValuePairs;

OptionSet(List<KeyValuePair> keyValuePairs) {
this.keyValuePairs = keyValuePairs;
OptionSet(KeyValuePair... keyValuePairs) {
this.keyValuePairs = new ArrayList<KeyValuePair>();
for (KeyValuePair keyValuePair : keyValuePairs) {
this.keyValuePairs.add(keyValuePair);
}
}

public List<KeyValuePair> getKeyValuePairs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import com.xebialabs.overthere.spi.AddressPortMapper;
import com.xebialabs.overthere.util.DefaultAddressPortMapper;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.xebialabs.overthere.util.OverthereUtils.checkArgument;
import static com.xebialabs.overthere.util.OverthereUtils.checkNotNull;
import static com.xebialabs.overthere.OperatingSystemFamily.WINDOWS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CIFS_PROTOCOL;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_ENABLE_HTTPS_DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import com.xebialabs.overthere.spi.Protocol;
import com.xebialabs.overthere.util.DefaultAddressPortMapper;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.xebialabs.overthere.util.OverthereUtils.checkArgument;
import static com.xebialabs.overthere.util.OverthereUtils.checkNotNull;
import static com.xebialabs.overthere.ConnectionOptions.OPERATING_SYSTEM;
import static com.xebialabs.overthere.ConnectionOptions.TEMPORARY_DIRECTORY_PATH;
import static com.xebialabs.overthere.OperatingSystemFamily.getLocalHostOperatingSystemFamily;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/xebialabs/overthere/local/LocalFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.xebialabs.overthere.ConnectionOptions;
import com.xebialabs.overthere.OverthereFile;
import com.xebialabs.overthere.RuntimeIOException;
import com.xebialabs.overthere.spi.BaseOverthereFile;

import static com.google.common.collect.Lists.newArrayList;
import static com.xebialabs.overthere.local.LocalConnection.LOCAL_PROTOCOL;

/**
Expand Down Expand Up @@ -162,7 +162,7 @@ public void mkdirs() {

@Override
public List<OverthereFile> listFiles() {
List<OverthereFile> list = newArrayList();
List<OverthereFile> list = new ArrayList<OverthereFile>();
for (File each : file.listFiles()) {
list.add(new LocalFile(connection, each));
}
Expand Down
Loading

0 comments on commit bf82f4f

Please sign in to comment.