use of org.tmatesoft.svn.core.SVNNodeKind in project Gargoyle by callakrsos.
the class CommandTest3 method scenarioTest.
/**
*
* ################# 시나리오 테스트 ###################
*
* 1. svn 디렉토리 파일목록만 추출.
*
* 2. 추출된 파일목록에서 컨텐츠 조회
*
* @작성자 : KYJ
* @작성일 : 2016. 5. 13.
*/
@Test
public void scenarioTest() {
List<SVNDirEntry> list = testServerManager.listEntry("/sos/pass-batch-core");
Optional<String> findFirst = list.stream().filter(e -> {
SVNNodeKind kind = e.getKind();
if (SVNNodeKind.FILE == kind)
return true;
return false;
}).map(e -> {
try {
SVNURL url = e.getURL();
SVNURL repositoryRoot = e.getRepositoryRoot();
String relativeURL = SVNURLUtil.getRelativeURL(repositoryRoot, url, true);
return relativeURL;
} catch (Exception e1) {
e1.printStackTrace();
}
return "error";
}).peek(e -> {
System.out.println(testServerManager.cat(e));
}).findFirst();
// 첫번째 데이터를 찾은후...
findFirst.ifPresent(url -> {
try {
File outDir = new File("c://sampleDir");
outDir.mkdir();
System.out.println("checout dir ::: " + outDir.getAbsolutePath());
System.out.println("checout url ::: " + url);
Long checkout = testServerManager.checkout(url, outDir);
System.out.println("result ::: " + checkout);
} catch (Exception e1) {
e1.printStackTrace();
}
});
}
use of org.tmatesoft.svn.core.SVNNodeKind in project oxTrust by GluuFederation.
the class SubversionService method checkRootSvnPath.
private boolean checkRootSvnPath(SVNClientManager clientManager, SVNURL repositoryURL) throws SVNException {
SVNRepository repository = SvnHelper.getSVNRepository(clientManager, repositoryURL);
// Check if root path exist
log.debug("Checking if root path exist");
SVNNodeKind nodeKind = SvnHelper.exist(repository, "");
if (nodeKind != SVNNodeKind.DIR) {
log.error("Failed to commit files to repository. Please check SVN URL gluuAppliance.properties");
return false;
}
return true;
}
use of org.tmatesoft.svn.core.SVNNodeKind in project Gargoyle by callakrsos.
the class SVNList method list.
/********************************
* 작성일 : 2016. 5. 4. 작성자 : KYJ
*
* path에 속하는 구성정보 조회
*
* @param path
* @param revision
* @param exceptionHandler
* @return
********************************/
public List<String> list(String path, String revision, Consumer<Exception> exceptionHandler) {
List<String> resultList = Collections.emptyList();
try {
SVNProperties fileProperties = new SVNProperties();
SVNRepository repository = getRepository();
Collection<SVNDirEntry> dir = repository.getDir(path, Long.parseLong(revision), fileProperties, new ArrayList<>());
resultList = dir.stream().map(d -> {
SVNNodeKind kind = d.getKind();
if (SVNNodeKind.DIR == kind) {
return d.getRelativePath().concat("/");
} else {
return d.getRelativePath();
}
}).collect(Collectors.toList());
} catch (SVNException e) {
LOGGER.error(ValueUtil.toString(e));
if (exceptionHandler != null)
exceptionHandler.accept(e);
}
return resultList;
}
use of org.tmatesoft.svn.core.SVNNodeKind in project Gargoyle by callakrsos.
the class DisplayFile method main.
/*
* args parameter is used to obtain a repository location URL, user's
* account name & password to authenticate him to the server, the file path
* in the rpository (the file path should be relative to the the
* path/to/repository part of the repository location URL).
*/
public static void main(String[] args) {
/*
* Default values:
*/
String url = "https://dev.naver.com/svn/gmes/AddressApp";
String name = "callakrsos";
String password = "zkffk88";
String filePath = ".classpath";
/*
* Initializes the library (it must be done before ever using the
* library itself)
*/
setupLibrary();
if (args != null) {
/*
* Obtains a repository location URL
*/
url = (args.length >= 1) ? args[0] : url;
/*
* Obtains a file path
*/
filePath = (args.length >= 2) ? args[1] : filePath;
/*
* Obtains an account name (will be used to authenticate the user to
* the server)
*/
name = (args.length >= 3) ? args[2] : name;
/*
* Obtains a password
*/
password = (args.length >= 4) ? args[3] : password;
}
SVNRepository repository = null;
try {
/*
* Creates an instance of SVNRepository to work with the repository.
* All user's requests to the repository are relative to the
* repository location used to create this SVNRepository. SVNURL is
* a wrapper for URL strings that refer to repository locations.
*/
repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
} catch (SVNException svne) {
/*
* Perhaps a malformed URL is the cause of this exception
*/
System.err.println("error while creating an SVNRepository for the location '" + url + "': " + svne.getMessage());
System.exit(1);
}
/*
* User's authentication information (name/password) is provided via an
* ISVNAuthenticationManager instance. SVNWCUtil creates a default
* authentication manager given user's name and password.
*
* Default authentication manager first attempts to use provided user
* name and password and then falls back to the credentials stored in
* the default Subversion credentials storage that is located in
* Subversion configuration area. If you'd like to use provided user
* name and password only you may use BasicAuthenticationManager class
* instead of default authentication manager:
*
* authManager = new BasicAuthenticationsManager(userName,
* userPassword);
*
* You may also skip this point - anonymous access will be used.
*/
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password);
repository.setAuthenticationManager(authManager);
/*
* This Map will be used to get the file properties. Each Map key is a
* property name and the value associated with the key is the property
* value.
*/
SVNProperties fileProperties = new SVNProperties();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
/*
* Checks up if the specified path really corresponds to a file. If
* doesn't the program exits. SVNNodeKind is that one who says what
* is located at a path in a revision. -1 means the latest revision.
*/
SVNNodeKind nodeKind = repository.checkPath(filePath, -1);
if (nodeKind == SVNNodeKind.NONE) {
System.err.println("There is no entry at '" + url + "'.");
System.exit(1);
} else if (nodeKind == SVNNodeKind.DIR) {
System.err.println("The entry at '" + url + "' is a directory while a file was expected.");
System.exit(1);
}
/*
* Gets the contents and properties of the file located at filePath
* in the repository at the latest revision (which is meant by a
* negative revision number).
*/
repository.getFile(filePath, -1, fileProperties, baos);
} catch (SVNException svne) {
System.err.println("error while fetching the file contents and properties: " + svne.getMessage());
System.exit(1);
}
/*
* Here the SVNProperty class is used to get the value of the
* svn:mime-type property (if any). SVNProperty is used to facilitate
* the work with versioned properties.
*/
String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
/*
* SVNProperty.isTextMimeType(..) method checks up the value of the
* mime-type file property and says if the file is a text (true) or not
* (false).
*/
boolean isTextType = SVNProperty.isTextMimeType(mimeType);
Iterator iterator = fileProperties.nameSet().iterator();
/*
* Displays file properties.
*/
while (iterator.hasNext()) {
String propertyName = (String) iterator.next();
String propertyValue = fileProperties.getStringValue(propertyName);
System.out.println("File property: " + propertyName + "=" + propertyValue);
}
/*
* Displays the file contents in the console if the file is a text.
*/
if (isTextType) {
System.out.println("File contents:");
System.out.println();
try {
baos.writeTo(System.out);
} catch (IOException ioe) {
ioe.printStackTrace();
}
} else {
System.out.println("File contents can not be displayed in the console since the mime-type property says that it's not a kind of a text file.");
}
/*
* Gets the latest revision number of the repository
*/
long latestRevision = -1;
try {
latestRevision = repository.getLatestRevision();
} catch (SVNException svne) {
System.err.println("error while fetching the latest repository revision: " + svne.getMessage());
System.exit(1);
}
System.out.println("");
System.out.println("---------------------------------------------");
System.out.println("Repository latest revision: " + latestRevision);
System.exit(0);
}
use of org.tmatesoft.svn.core.SVNNodeKind in project Gargoyle by callakrsos.
the class SVNCat method cat.
/**
* @작성자 : KYJ
* @작성일 : 2016. 6. 13.
* @param path
* @param revision
* @param encoding
* @param exceptionHandler
* @return
*/
public String cat(String path, String revision, String encoding, Consumer<Exception> exceptionHandler) {
String result = "";
SVNProperties fileProperties = new SVNProperties();
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
/*
* Checks up if the specified path really corresponds to a file. If
* doesn't the program exits. SVNNodeKind is that one who says what
* is located at a path in a revision. -1 means the latest revision.
*/
String _path = path;
try {
_path = URLDecoder.decode(_path, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
SVNRepository repository = getRepository();
SVNNodeKind nodeKind = repository.checkPath(_path, -1);
if (nodeKind == SVNNodeKind.NONE) {
if (exceptionHandler != null) {
exceptionHandler.accept(new RuntimeException("There is no entry at '" + getUrl() + "'."));
} else
throw new RuntimeException("There is no entry at '" + getUrl() + "'.");
} else if (nodeKind == SVNNodeKind.DIR) {
if (exceptionHandler != null) {
exceptionHandler.accept(new RuntimeException("The entry at '" + getUrl() + "' is a directory while a file was expected."));
} else
throw new RuntimeException("The entry at '" + getUrl() + "' is a directory while a file was expected.");
}
/*
* Gets the contents and properties of the file located at filePath
* in the repository at the latest revision (which is meant by a
* negative revision number).
*/
long parseLong = -1;
try {
parseLong = Long.parseLong(revision);
} catch (NumberFormatException e) {
}
repository.getFile(_path, parseLong, fileProperties, baos);
/*
* Here the SVNProperty class is used to get the value of the
* svn:mime-type property (if any). SVNProperty is used to
* facilitate the work with versioned properties.
*/
String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
/*
* SVNProperty.isTextMimeType(..) method checks up the value of the
* mime-type file property and says if the file is a text (true) or
* not (false).
*/
boolean isTextType = SVNProperty.isTextMimeType(mimeType);
Iterator<String> iterator = fileProperties.nameSet().iterator();
/*
* Displays file properties.
*/
while (iterator.hasNext()) {
String propertyName = iterator.next();
String propertyValue = fileProperties.getStringValue(propertyName);
LOGGER.debug("File property: " + propertyName + "=" + propertyValue);
}
/*
* Displays the file contents in the console if the file is a text.
*/
if (isTextType) {
// try (StringOutputStream out = new StringOutputStream()) {
// baos.writeTo(out);
// out.getString();
result = baos.toString(encoding);
// }
} else /*
* 2017.2.28
* binay type은 무거운 데이터를 읽어들일수있는 가능성때문에 여기서 제외시켜놓겠음.
*/
if (SVNProperty.isBinaryMimeType(mimeType)) {
//baos.toString(encoding);
result = mimeType + " is not support.";
} else {
LOGGER.debug("File contents can not be displayed in the console since the mime-type property says that it's not a kind of a text file.");
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
if (exceptionHandler != null)
exceptionHandler.accept(e);
}
return result;
}
Aggregations