forked from top-master/GradleCopy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopythread.cpp
More file actions
111 lines (91 loc) · 4.25 KB
/
copythread.cpp
File metadata and controls
111 lines (91 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "copythread.h"
#include <QDebug>
CopyThread::~CopyThread()
{
qWarning() << "CopyThread deleted";
}
void CopyThread::run() {
emit statusChanged("running");
//prepare arguments
if(!target.endsWith(QLatin1Char('/')))
target.append(QLatin1Char('/'));
source.setFilter(source.filter() | QDir::NoDotAndDotDot);
if(operation == CopyLibraries) {
QDirIterator it(source);
while(it.hasNext()) {
QDir domainDir = QDir(it.next());
domainDir.setFilter(domainDir.filter() | QDir::NoDotAndDotDot);
const QString domainName = domainDir.dirName().replace(QLatin1Char('.'), QLatin1Char('/'));
const QString domainPath = target
+ domainName + QLatin1Char('/');
emit domainChanged(domainName);
QDirIterator it(domainDir);
while(it.hasNext()) {
QDir libraryDir = QDir(it.next());
libraryDir.setFilter(libraryDir.filter() | QDir::NoDotAndDotDot);
const QString libraryPath = domainPath + libraryDir.dirName() + QLatin1Char('/');
QDirIterator it(libraryDir);
while(it.hasNext()) {
QDir versionDir = QDir(it.next());
versionDir.setFilter(versionDir.filter() | QDir::NoDotAndDotDot);
const QString versionPath = libraryPath + versionDir.dirName() + QLatin1Char('/');
if(!dryRun && !versionDir.mkpath(versionPath)) {
qWarning() << "failed to make path:" << versionPath;
}
QDirIterator it(versionDir);
while(it.hasNext()) {
QDir idDir = QDir(it.next());
idDir.setFilter(idDir.filter() | QDir::NoDotAndDotDot
| QDir::Files);
QDirIterator it(idDir);
while(it.hasNext()) {
const QString sourcePath = it.next();
QFileInfo fileInfo(sourcePath);
const QString targetPath = versionPath + fileInfo.fileName();
if(!dryRun) {
QFileInfo target(targetPath);
// if(!target.exists()) {
QFile::copy(sourcePath, targetPath);
// } else {
// qWarning() << "file already exists:" << targetPath;
// }
} else
qDebug() << "copy:" << sourcePath << "to:" << targetPath;
}
}
}
}
}
} else if(operation == GetLinkList) {
QStringList remoteLinks;
QStringList localFiles;
QLatin1Literal providerSite("https://repo1.maven.org/maven2/");
//search for any library that is not ready for download
QDirIterator it(target, QStringList() << "*.pom" << "*.pom.backup", QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) {
const QString pomPath = it.next();
const QString basePath = baseFromPom(pomPath);
const QString jarPath = basePath + QLatin1Literal(".jar");
QFileInfo jarInfo(jarPath);
const QString aarPath = basePath + QLatin1Literal(".aar");
QFileInfo aarInfo(aarPath);
if(jarInfo.exists() == false && aarInfo.exists() == false) {
QString link;
link.reserve(providerSite.size() + (jarPath.length() - target.length()));
link += providerSite;
link += jarPath.right(jarPath.length() - target.length());
localFiles += jarPath;
remoteLinks += link;
}
}
emit listReady(providerSite, remoteLinks, localFiles);
}
emit statusChanged("finished");
}
QString CopyThread::baseFromPom(const QString &pomPath) const
{
const QLatin1Literal pomBackupExt = getPomBackupExtension();
if(pomPath.endsWith(pomBackupExt))
return pomPath.left(pomPath.size() - pomBackupExt.size());
return pomPath.left(pomPath.size() - 4);
}