2017-05-09 18:46:52 +02:00
|
|
|
package org.gcube.dataanalysis.dataminer.poolmanager.util;
|
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.File;
|
2017-12-15 13:01:42 +01:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
2017-11-08 16:12:38 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.Configuration;
|
2017-05-17 18:16:25 +02:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Dependency;
|
2017-12-15 16:46:26 +01:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.exception.GenericException;
|
2017-12-15 13:01:42 +01:00
|
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.util.exception.SVNCommitException;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.tmatesoft.svn.core.SVNCommitInfo;
|
|
|
|
import org.tmatesoft.svn.core.SVNErrorMessage;
|
2017-05-09 18:46:52 +02:00
|
|
|
import org.tmatesoft.svn.core.SVNException;
|
2017-07-26 11:39:02 +02:00
|
|
|
import org.tmatesoft.svn.core.SVNNodeKind;
|
2017-05-09 18:46:52 +02:00
|
|
|
import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
|
|
|
|
import org.tmatesoft.svn.core.internal.wc.admin.SVNChecksumInputStream;
|
|
|
|
import org.tmatesoft.svn.core.io.ISVNEditor;
|
|
|
|
import org.tmatesoft.svn.core.io.SVNRepository;
|
|
|
|
import org.tmatesoft.svn.core.io.diff.SVNDeltaGenerator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by ggiammat on 5/9/17.
|
|
|
|
*/
|
2017-11-29 16:29:01 +01:00
|
|
|
public abstract class SVNUpdater {
|
2017-05-09 18:46:52 +02:00
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
private SVNRepository svnRepository;
|
2017-11-29 16:29:01 +01:00
|
|
|
private Configuration configuration;
|
2017-12-15 13:01:42 +01:00
|
|
|
private Logger logger;
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-11-29 16:29:01 +01:00
|
|
|
public SVNUpdater(Configuration configuration) throws SVNException {
|
|
|
|
this.configuration = configuration;
|
|
|
|
this.svnRepository = SVNRepositoryManager.getInstance(configuration).getSvnRepository();
|
2017-12-15 13:01:42 +01:00
|
|
|
this.logger = LoggerFactory.getLogger(SVNUpdater.class);
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
2017-07-06 14:54:04 +02:00
|
|
|
|
2017-07-07 15:57:46 +02:00
|
|
|
// public void updateRPRotoDeps(Algorithm algorithm) {
|
|
|
|
// this.updateSVN(this.configuration.getSVNRProtoOSDepsList(), algorithm.getOSDependencies());
|
|
|
|
// this.updateSVN(this.configuration.getSVNRProtoCRANDepsList(), algorithm.getCranDependencies());
|
|
|
|
// this.updateSVN(this.configuration.getSVNRProtoGitHubDepsList(), algorithm.getGitHubDependencies());
|
|
|
|
// }
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-07-26 21:21:07 +02:00
|
|
|
|
|
|
|
|
2017-11-29 16:29:01 +01:00
|
|
|
public String getDependencyFile(String language/*, String env*/)
|
|
|
|
{
|
|
|
|
return getDependencyFile(this.configuration,language);
|
2017-10-27 19:18:42 +02:00
|
|
|
}
|
2017-09-20 18:51:21 +02:00
|
|
|
|
|
|
|
|
2017-07-26 21:21:07 +02:00
|
|
|
|
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
|
|
|
|
private String getDependencyFile (Configuration configuration, String language)
|
|
|
|
{
|
2017-12-15 13:01:42 +01:00
|
|
|
this.logger.debug("Getting dependency file for language "+language);
|
|
|
|
|
|
|
|
switch (language)
|
|
|
|
{
|
2017-10-27 19:18:42 +02:00
|
|
|
case "R":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNCRANDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "R-blackbox":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNRBDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "Java":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNJavaDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "Knime-Workflow":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNKWDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "Linux-compiled":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNLinuxCompiledDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "Octave":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNOctaveDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "Python":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNPythonDepsList();
|
2018-10-26 10:46:20 +02:00
|
|
|
case "Python3.6":
|
2018-11-05 17:29:54 +01:00
|
|
|
return configuration.getSVNPython3_6DepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "Pre-Installed":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNPreInstalledDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
case "Windows-compiled":
|
2017-11-08 16:12:38 +01:00
|
|
|
return configuration.getSVNWCDepsList();
|
2017-10-27 19:18:42 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 17:34:45 +02:00
|
|
|
|
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
public boolean updateSVNAlgorithmList(Algorithm algorithm, String targetVRE, String category, String algorithm_type, String user/*, String env*/)
|
2017-11-29 16:29:01 +01:00
|
|
|
{
|
2017-12-15 13:01:42 +01:00
|
|
|
return this.updateSVNAlgorithmList(this.configuration.getSVNAlgorithmsList(), algorithm, targetVRE, category, algorithm_type, user);
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
2017-10-27 23:30:20 +02:00
|
|
|
|
2017-11-29 16:29:01 +01:00
|
|
|
|
2017-10-27 23:30:20 +02:00
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
public void updateAlgorithmFiles(File a) throws SVNException, SVNCommitException{
|
2017-10-06 16:07:09 +02:00
|
|
|
//this.updateAlgorithmList(this.configuration.getSVNMainAlgoRepo(), a);
|
2017-11-29 16:29:01 +01:00
|
|
|
this.updateAlgorithmList(this.configuration.getRepository(), a);
|
2017-07-26 11:39:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-29 16:29:01 +01:00
|
|
|
|
2017-10-27 19:18:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
private void updateAlgorithmList(String svnMainAlgoRepo, File algorithmsFile) throws SVNException, SVNCommitException
|
|
|
|
{
|
|
|
|
this.logger.debug("Adding .jar file: " + algorithmsFile + " to repository " + svnMainAlgoRepo);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
if (fileExists(svnMainAlgoRepo+File.separator+algorithmsFile.getName(), -1))
|
|
|
|
{
|
|
|
|
this.updateFile(new FileInputStream(algorithmsFile), svnMainAlgoRepo, algorithmsFile.getName());
|
2017-07-26 11:39:02 +02:00
|
|
|
|
|
|
|
}
|
2017-12-15 13:01:42 +01:00
|
|
|
else this.putFile(new FileInputStream(algorithmsFile), svnMainAlgoRepo,algorithmsFile.getName());
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException e)
|
|
|
|
{
|
|
|
|
this.logger.error("Temporary algorithm file not found: this exception should not happen",e);
|
2017-07-26 11:39:02 +02:00
|
|
|
}
|
2017-12-15 13:01:42 +01:00
|
|
|
finally
|
|
|
|
{
|
|
|
|
this.svnRepository.closeSession();
|
2017-07-26 11:39:02 +02:00
|
|
|
}
|
2017-12-15 13:01:42 +01:00
|
|
|
}
|
2017-07-26 11:39:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
public void putFile(FileInputStream fileInputSreeam, String destinationFolder, String fileName) throws SVNException, SVNCommitException
|
|
|
|
{
|
|
|
|
this.logger.debug("Putting new file on the SVN repository");
|
2017-07-26 11:39:02 +02:00
|
|
|
final ISVNEditor commitEditor = svnRepository.getCommitEditor("Add algorithm to list", null);
|
|
|
|
commitEditor.openRoot(-1);
|
|
|
|
commitEditor.openDir(destinationFolder, -1);
|
2017-12-15 13:01:42 +01:00
|
|
|
String filePath = destinationFolder + "/" + fileName;
|
|
|
|
commitEditor.addFile(filePath, null, -1);
|
|
|
|
commitEditor.applyTextDelta(filePath, null);
|
|
|
|
SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
|
|
|
|
String checksum = deltaGenerator.sendDelta(filePath, fileInputSreeam, commitEditor, true);
|
|
|
|
commitEditor.closeFile(filePath, checksum);
|
|
|
|
commitEditor.closeDir();
|
|
|
|
commitEditor.closeDir();
|
|
|
|
SVNCommitInfo info = commitEditor.closeEdit();
|
|
|
|
SVNErrorMessage errorMessage = info.getErrorMessage();
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
if (errorMessage != null)
|
|
|
|
{
|
|
|
|
this.logger.error("Operation failed: "+errorMessage.getFullMessage());
|
2017-12-15 16:46:26 +01:00
|
|
|
throw new SVNCommitException(errorMessage,fileName);
|
2017-07-26 11:39:02 +02:00
|
|
|
}
|
2017-12-15 13:01:42 +01:00
|
|
|
|
|
|
|
this.logger.debug("Operation completed");
|
|
|
|
}
|
2017-07-26 11:39:02 +02:00
|
|
|
|
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
public void updateFile(FileInputStream fileInputStream, String destinationFolder, String fileName) throws SVNException, SVNCommitException {
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
this.logger.debug("Updating existing file on the SVN repository");
|
|
|
|
final ISVNEditor commitEditor = svnRepository.getCommitEditor("Updating algorithm", null);
|
2017-07-26 11:39:02 +02:00
|
|
|
commitEditor.openRoot(-1);
|
|
|
|
commitEditor.openDir(destinationFolder, -1);
|
2017-12-15 13:01:42 +01:00
|
|
|
String filePath = destinationFolder + "/" + fileName;
|
|
|
|
// if (fileExists(filePath, -1)) { // updating existing file
|
|
|
|
commitEditor.openFile(filePath, -1);
|
|
|
|
//} else { // creating new file
|
|
|
|
//commitEditor.addFile(filePath, null, -1);
|
|
|
|
//}
|
|
|
|
commitEditor.applyTextDelta(filePath, null);
|
|
|
|
SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
|
|
|
|
String checksum = deltaGenerator.sendDelta(filePath, fileInputStream, commitEditor, true);
|
|
|
|
commitEditor.closeFile(filePath, checksum);
|
|
|
|
commitEditor.closeDir();
|
|
|
|
commitEditor.closeDir();
|
|
|
|
SVNCommitInfo info = commitEditor.closeEdit();
|
|
|
|
SVNErrorMessage errorMessage = info.getErrorMessage();
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
if (errorMessage != null)
|
|
|
|
{
|
|
|
|
this.logger.error("Operation failed: "+errorMessage.getFullMessage());
|
2017-12-15 16:46:26 +01:00
|
|
|
|
|
|
|
throw new SVNCommitException(errorMessage,fileName+" to be updated");
|
2017-07-26 11:39:02 +02:00
|
|
|
}
|
2017-12-15 13:01:42 +01:00
|
|
|
|
|
|
|
this.logger.debug("Operation completed");
|
|
|
|
}
|
2017-07-26 11:39:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean fileExists(String path, long revision) throws SVNException {
|
|
|
|
SVNNodeKind kind = svnRepository.checkPath(path, revision);
|
|
|
|
if (kind == SVNNodeKind.FILE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
// public static ByteArrayInputStream reteriveByteArrayInputStream(File file) throws IOException
|
|
|
|
// {
|
|
|
|
//
|
|
|
|
// return new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
|
|
|
|
// }
|
2017-07-26 11:39:02 +02:00
|
|
|
|
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
private boolean updateSVNAlgorithmList(String file, Algorithm algorithm, String targetVRE, String category, String algorithm_type, String user/*, String env*/)
|
|
|
|
{
|
|
|
|
boolean response = false;
|
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
try {
|
2017-12-15 13:01:42 +01:00
|
|
|
this.logger.debug("Updating algorithm list: " + file);
|
2017-07-06 17:34:45 +02:00
|
|
|
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
svnRepository.getFile(file, SVNRepository.INVALID_REVISION, null, byteArrayOutputStream);
|
|
|
|
String lines[] = byteArrayOutputStream.toString().split("\\r?\\n");
|
2017-09-01 17:24:42 +02:00
|
|
|
|
|
|
|
List<String> newContent = new LinkedList<>(Arrays.asList(lines));
|
|
|
|
|
|
|
|
// check if the algorithm is already in the list (match the class name) and delete the content
|
2017-07-06 17:34:45 +02:00
|
|
|
for (String l : lines) {
|
|
|
|
if (l.contains(algorithm.getClazz())) {
|
2017-09-01 17:24:42 +02:00
|
|
|
newContent.remove(l);
|
|
|
|
//System.out.println("Not updating algorithm list beacuse already present");
|
|
|
|
//return;
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 17:24:42 +02:00
|
|
|
// the algorithm is not in the list or must be overwritten cause some modification. Add it
|
2017-09-20 18:51:21 +02:00
|
|
|
newContent.add(this.generateAlgorithmEntry(algorithm, targetVRE, category,algorithm_type/*, env*/));
|
2017-07-06 17:34:45 +02:00
|
|
|
// Collections.sort(newContent);
|
|
|
|
|
|
|
|
final SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
|
|
|
|
|
|
|
|
byte[] originalContents = byteArrayOutputStream.toByteArray();
|
|
|
|
|
|
|
|
final ISVNEditor commitEditor = svnRepository.getCommitEditor("update algorithm list", null);
|
|
|
|
commitEditor.openRoot(-1);
|
|
|
|
commitEditor.openFile(file, -1);
|
|
|
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
2017-10-30 22:38:11 +01:00
|
|
|
for (String line : newContent) {
|
2017-07-06 17:34:45 +02:00
|
|
|
baos.write(line.getBytes());
|
|
|
|
baos.write("\n".getBytes());
|
|
|
|
}
|
|
|
|
byte[] bytes = baos.toByteArray();
|
|
|
|
|
|
|
|
commitEditor.applyTextDelta(file, md5(originalContents));
|
|
|
|
|
|
|
|
final String checksum = deltaGenerator.sendDelta(file, new ByteArrayInputStream(originalContents), 0,
|
|
|
|
new ByteArrayInputStream(bytes), commitEditor, true);
|
|
|
|
commitEditor.closeFile(file, checksum);
|
2017-12-15 13:01:42 +01:00
|
|
|
SVNCommitInfo info = commitEditor.closeEdit();
|
|
|
|
SVNErrorMessage errorMessage = info.getErrorMessage();
|
|
|
|
|
|
|
|
if (errorMessage != null)
|
|
|
|
{
|
|
|
|
this.logger.error("Operation failed: "+errorMessage.getFullMessage());
|
|
|
|
response = false;
|
|
|
|
}
|
|
|
|
else response = true;
|
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
this.logger.error("Unable to commit algorithm list",ex);
|
|
|
|
response = false;
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
|
|
|
|
2017-12-15 13:01:42 +01:00
|
|
|
finally
|
|
|
|
{
|
2017-07-06 17:34:45 +02:00
|
|
|
svnRepository.closeSession();
|
|
|
|
}
|
2017-12-15 13:01:42 +01:00
|
|
|
|
|
|
|
return response;
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 19:18:42 +02:00
|
|
|
|
2017-09-20 18:51:21 +02:00
|
|
|
public String generateAlgorithmEntry(Algorithm algorithm, String targetVRE, String category, String algorithm_type/*,String env*/) throws ParseException {
|
2017-09-01 17:50:01 +02:00
|
|
|
//Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
2017-09-01 18:59:47 +02:00
|
|
|
//long unixTime = System.currentTimeMillis() / 1000L;
|
2017-09-01 17:50:01 +02:00
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
StringBuffer sb = new StringBuffer("| ");
|
|
|
|
sb.append(algorithm.getName() + " | ");
|
|
|
|
sb.append(algorithm.getFullname() + " | ");
|
2017-08-29 17:43:31 +02:00
|
|
|
sb.append(category + " | ");
|
2017-10-04 15:13:05 +02:00
|
|
|
sb.append("DataMinerPoolManager | ");
|
2017-07-06 17:34:45 +02:00
|
|
|
sb.append("<notextile>./addAlgorithm.sh " + algorithm.getName() + " " + algorithm.getCategory() + " "
|
2017-08-29 17:43:31 +02:00
|
|
|
+ algorithm.getClazz() + " " + targetVRE + " " + algorithm_type + " N "
|
2017-07-06 17:34:45 +02:00
|
|
|
+ algorithm.getPackageURL() + " \"" + algorithm.getDescription() + "\" </notextile> | ");
|
2017-09-01 17:24:42 +02:00
|
|
|
sb.append("none | ");
|
2017-09-01 18:59:47 +02:00
|
|
|
sb.append(this.getTimeZone() + " | ");
|
2017-10-27 19:18:42 +02:00
|
|
|
|
2017-12-20 12:01:01 +01:00
|
|
|
this.logger.info("Algo details: "+sb.toString());
|
2017-10-27 19:18:42 +02:00
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-15 16:46:26 +01:00
|
|
|
public Collection<String> getUndefinedDependencies(String file, Collection<Dependency> deps) throws GenericException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// SendMail sm = new SendMail();
|
|
|
|
// NotificationHelper nh = new NotificationHelper();
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-12-15 16:46:26 +01:00
|
|
|
List<String> undefined = new LinkedList<String>();
|
|
|
|
|
|
|
|
//to fix in next release: if the file is not present for that language in the service.properties then skip and return null list of string
|
|
|
|
//just to uncomment the following lines
|
2017-09-20 18:51:21 +02:00
|
|
|
|
2017-12-15 16:46:26 +01:00
|
|
|
if(file.isEmpty()){
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.logger.debug("Checking dependencies list: " + file);
|
|
|
|
|
2017-11-29 16:29:01 +01:00
|
|
|
|
2017-12-15 16:46:26 +01:00
|
|
|
List<String> validDependencies = new LinkedList<String>();
|
2017-10-10 16:25:11 +02:00
|
|
|
|
2017-12-15 16:46:26 +01:00
|
|
|
for (String singlefile: CheckMethod.getFiles(file)){
|
|
|
|
|
|
|
|
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
svnRepository.getFile(singlefile, SVNRepository.INVALID_REVISION, null, byteArrayOutputStream);
|
|
|
|
|
|
|
|
for(String l: byteArrayOutputStream.toString().split("\\r?\\n")){
|
|
|
|
validDependencies.add(l.trim());
|
|
|
|
}}
|
|
|
|
|
|
|
|
this.logger.debug("Valid dependencies are: "+validDependencies);
|
|
|
|
for(Dependency d: deps){
|
|
|
|
String depName = d.getName();
|
|
|
|
if(!validDependencies.contains(depName)){
|
|
|
|
undefined.add(depName);
|
|
|
|
}
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
2017-12-15 16:46:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
//
|
|
|
|
//
|
2017-07-06 17:34:45 +02:00
|
|
|
// for (String a : lines) {
|
|
|
|
// for (String b : ldep) {
|
|
|
|
// if (b.equals(a)) {
|
|
|
|
// System.out.println("The following dependency is correctly written: " + b);
|
|
|
|
// } else
|
2017-12-15 16:46:26 +01:00
|
|
|
//
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// boolean check = false;
|
|
|
|
// try {
|
|
|
|
// System.out.println("Checking dependencies list: " + file);
|
|
|
|
// final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
// svnRepository.getFile(file, SVNRepository.INVALID_REVISION, null, byteArrayOutputStream);
|
|
|
|
// String lines[] = byteArrayOutputStream.toString().split("\\r?\\n");
|
|
|
|
//
|
|
|
|
// // if(deps.isEmpty()){
|
|
|
|
// // sm.sendNotification(nh.getFailedSubject(), nh.getFailedBody());
|
|
|
|
// // Exception e = new Exception("No dependency specified for this
|
|
|
|
// // algorithm");
|
|
|
|
// // throw e;
|
|
|
|
// //
|
|
|
|
// // }
|
|
|
|
//
|
|
|
|
// // else if (!deps.isEmpty()) {
|
|
|
|
// List<String> ldep = new LinkedList<>();
|
|
|
|
// for (Dependency d : deps) {
|
|
|
|
// ldep.add(d.getName());
|
|
|
|
// }
|
|
|
|
// for (String a : lines) {
|
|
|
|
// for (String b : ldep) {
|
|
|
|
// if (b.equals(a)) {
|
|
|
|
// System.out.println("The following dependency is correctly written: " + b);
|
|
|
|
// check = true;
|
|
|
|
// } else
|
|
|
|
// check = false;
|
|
|
|
//
|
|
|
|
// }
|
2017-07-06 17:34:45 +02:00
|
|
|
// }
|
2017-12-15 16:46:26 +01:00
|
|
|
// // }
|
|
|
|
// } catch (Exception a) {
|
|
|
|
// a.getMessage();
|
2017-07-06 17:34:45 +02:00
|
|
|
// }
|
2017-12-15 16:46:26 +01:00
|
|
|
//
|
|
|
|
// return check;
|
|
|
|
} catch (SVNException e)
|
|
|
|
{
|
|
|
|
throw new GenericException(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean checkIfAvaialable(String file, Collection<Dependency> deps) throws SVNException {
|
2017-11-29 16:29:01 +01:00
|
|
|
//SendMail sm = new SendMail();
|
|
|
|
//NotificationHelper nh = new NotificationHelper();
|
2017-07-06 17:34:45 +02:00
|
|
|
|
|
|
|
boolean check = false;
|
|
|
|
try {
|
2017-12-20 12:01:01 +01:00
|
|
|
this.logger.info("Checking dependencies list: " + file);
|
2017-07-06 17:34:45 +02:00
|
|
|
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
svnRepository.getFile(file, SVNRepository.INVALID_REVISION, null, byteArrayOutputStream);
|
|
|
|
String lines[] = byteArrayOutputStream.toString().split("\\r?\\n");
|
|
|
|
|
|
|
|
// if(deps.isEmpty()){
|
|
|
|
// sm.sendNotification(nh.getFailedSubject(), nh.getFailedBody());
|
|
|
|
// Exception e = new Exception("No dependency specified for this
|
|
|
|
// algorithm");
|
|
|
|
// throw e;
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else if (!deps.isEmpty()) {
|
2017-07-05 17:50:42 +02:00
|
|
|
List<String> ldep = new LinkedList<>();
|
|
|
|
for (Dependency d : deps) {
|
|
|
|
ldep.add(d.getName());
|
|
|
|
}
|
|
|
|
for (String a : lines) {
|
|
|
|
for (String b : ldep) {
|
|
|
|
if (b.equals(a)) {
|
2017-07-06 17:34:45 +02:00
|
|
|
System.out.println("The following dependency is correctly written: " + b);
|
2017-07-05 17:50:42 +02:00
|
|
|
check = true;
|
|
|
|
} else
|
|
|
|
check = false;
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-07-05 17:50:42 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 17:34:45 +02:00
|
|
|
// }
|
2017-12-20 12:01:01 +01:00
|
|
|
} catch (Exception a)
|
|
|
|
{
|
|
|
|
this.logger.error(a.getMessage(),a);
|
|
|
|
|
2017-07-05 17:50:42 +02:00
|
|
|
}
|
2017-07-06 17:34:45 +02:00
|
|
|
|
2017-07-05 17:50:42 +02:00
|
|
|
return check;
|
2017-07-06 17:34:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateSVN(String file, Collection<Dependency> deps) {
|
|
|
|
try {
|
2017-12-20 12:01:01 +01:00
|
|
|
this.logger.info("Updating dependencies list: " + file);
|
2017-07-06 17:34:45 +02:00
|
|
|
|
|
|
|
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
svnRepository.getFile(file, SVNRepository.INVALID_REVISION, null, byteArrayOutputStream);
|
|
|
|
String lines[] = byteArrayOutputStream.toString().split("\\r?\\n");
|
|
|
|
|
|
|
|
List<String> ldep = new LinkedList<>();
|
|
|
|
for (Dependency d : deps) {
|
|
|
|
ldep.add(d.getName());
|
|
|
|
}
|
|
|
|
List<String> aa = this.checkMatch(lines, ldep);
|
|
|
|
Collections.sort(aa);
|
|
|
|
|
|
|
|
final SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
|
|
|
|
|
|
|
|
byte[] originalContents = byteArrayOutputStream.toByteArray();
|
|
|
|
|
|
|
|
final ISVNEditor commitEditor = svnRepository.getCommitEditor("update dependencies", null);
|
|
|
|
commitEditor.openRoot(-1);
|
|
|
|
commitEditor.openFile(file, -1);
|
|
|
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
for (String line : aa) {
|
|
|
|
baos.write(line.getBytes());
|
|
|
|
baos.write("\n".getBytes());
|
2017-10-30 22:38:11 +01:00
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
}
|
|
|
|
byte[] bytes = baos.toByteArray();
|
|
|
|
|
|
|
|
commitEditor.applyTextDelta(file, md5(originalContents));
|
|
|
|
|
|
|
|
final String checksum = deltaGenerator.sendDelta(file, new ByteArrayInputStream(originalContents), 0,
|
|
|
|
new ByteArrayInputStream(bytes), commitEditor, true);
|
2017-10-30 22:38:11 +01:00
|
|
|
|
|
|
|
|
2017-07-06 17:34:45 +02:00
|
|
|
commitEditor.closeFile(file, checksum);
|
|
|
|
commitEditor.closeEdit();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
svnRepository.closeSession();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String md5(byte[] contents) {
|
|
|
|
final byte[] tmp = new byte[1024];
|
|
|
|
final SVNChecksumInputStream checksumStream = new SVNChecksumInputStream(new ByteArrayInputStream(contents),
|
|
|
|
"md5");
|
|
|
|
try {
|
|
|
|
while (checksumStream.read(tmp) > 0) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
return checksumStream.getDigest();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// never happens
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
} finally {
|
|
|
|
SVNFileUtil.closeFile(checksumStream);
|
|
|
|
}
|
2017-07-05 17:50:42 +02:00
|
|
|
}
|
2017-07-06 17:34:45 +02:00
|
|
|
public List<String> checkMatch(String[] lines, List<String> ls) {
|
|
|
|
Set<String> ss = new HashSet<String>(ls);
|
|
|
|
ss.addAll(Arrays.asList(lines));
|
|
|
|
return new ArrayList<>(ss);
|
|
|
|
}
|
2017-05-09 18:46:52 +02:00
|
|
|
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-09-01 18:59:47 +02:00
|
|
|
public String getTimeZone() throws ParseException{
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
cal.getTime();
|
|
|
|
DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
|
2017-10-27 19:18:42 +02:00
|
|
|
Date fromDate = formatter.parse(cal.getTime().toString());
|
2017-09-01 18:59:47 +02:00
|
|
|
TimeZone central = TimeZone.getTimeZone("UTC");
|
|
|
|
formatter.setTimeZone(central);
|
2017-12-20 12:01:01 +01:00
|
|
|
this.logger.info(formatter.format(fromDate));
|
2017-09-01 18:59:47 +02:00
|
|
|
return formatter.format(fromDate);
|
|
|
|
}
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-09-01 18:59:47 +02:00
|
|
|
public static void main(String[] args) throws SVNException, ParseException {
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-11-08 16:12:38 +01:00
|
|
|
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-11-29 16:29:01 +01:00
|
|
|
// SVNUpdater c = new SVNUpdater();
|
2017-07-26 11:39:02 +02:00
|
|
|
|
|
|
|
//File a = new File("/home/ngalante/Desktop/testCiro");
|
2017-09-01 17:24:42 +02:00
|
|
|
//File b = new File ("/home/ngalante/Desktop/testB");
|
2017-09-01 18:59:47 +02:00
|
|
|
//long unixTime = System.currentTimeMillis() / 1000L;
|
|
|
|
//System.out.println(unixTime);
|
2017-07-26 11:39:02 +02:00
|
|
|
//c.updateAlgorithmFiles(a);
|
2017-09-01 17:24:42 +02:00
|
|
|
//c.updateAlgorithmFiles(b);
|
2017-09-01 18:59:47 +02:00
|
|
|
//Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
2017-07-26 11:39:02 +02:00
|
|
|
|
2017-09-01 18:59:47 +02:00
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
cal.getTime();
|
|
|
|
DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
|
2017-10-27 19:18:42 +02:00
|
|
|
Date fromDate = formatter.parse(cal.getTime().toString());
|
2017-09-01 18:59:47 +02:00
|
|
|
TimeZone central = TimeZone.getTimeZone("UTC");
|
|
|
|
formatter.setTimeZone(central);
|
|
|
|
System.out.println(formatter.format(fromDate));
|
2017-07-26 11:39:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-09 18:46:52 +02:00
|
|
|
}
|