-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcopythread.cpp
145 lines (117 loc) · 5.03 KB
/
copythread.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "copythread.h"
#include "project-info.h"
#include <QDebug>
CopyThread::~CopyThread()
{
qDebug("%s operation completed.", this->operation == CopyLibraries
? "Copy"
: "Scan-for-missing");
}
void CopyThread::run() {
emit statusChanged("running");
//prepare arguments
if(!m_target.endsWith(QLatin1Char('/')))
m_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 = m_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();
// Don't even log binary-same gradle-caches
// (God knows why Gradle did re-download them).
QFileInfo target(targetPath);
if (target.exists()
&& ProjectInfo::binarySame(targetPath, sourcePath)
) {
continue;
}
if(!dryRun) {
QFile::copy(sourcePath, targetPath);
} else
qDebug() << "copy:" << sourcePath << "to:" << targetPath;
}
}
}
}
}
} else if(operation == GetLinkList) {
QStringList remoteLinks;
QStringList localFiles;
QStringList filters;
filters.reserve(2);
filters << "*.pom";
filters << "*.pom.backup";
//search for any library that is not ready for download
QDirIterator it(m_target, filters, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) {
const QString pomPath = it.next();
// Parse POM.
ProjectInfo info(pomPath);
// Excludes pom-only packages.
if (info.parse()) {
// Undo old GradleCopy version's mistakes.
if (info.isBackup() && info.isDownloaded()) {
info.setVerbose(false);
info.restoreIncomplete();
info.setVerbose(true);
// Rename may fail, else could do:
// ```
// continue;
// ```
}
if (info.isParent()) {
// TODO: include dependencies of pom-only packages
// (into `remoteLinks`, if they don't exist locally).
continue;
}
}
if ( ! info.isComplete()) {
const QString &path = info.packagePath();
// Skip duplicates.
#ifdef Q_OS_WIN
const Qt::CaseSensitivity fileCasing = Qt::CaseInsensitive;
#else
const Qt::CaseSensitivity fileCasing = Qt::CaseSensitive;
#endif
if (localFiles.contains(path, fileCasing)) {
continue;
}
QString link;
link.reserve(path.length() - m_target.length());
link += path.right(path.length() - m_target.length());
localFiles += path;
remoteLinks += link;
}
}
emit listReady(remoteLinks, localFiles);
}
emit statusChanged("finished");
}