-
Notifications
You must be signed in to change notification settings - Fork 4
/
project-info.h
171 lines (143 loc) · 4.37 KB
/
project-info.h
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef POM_INFO_H
#define POM_INFO_H
#include <QtCore/QStringList>
namespace ThreeState {
enum Type {
Unknown = -1,
False = 0,
True = 1,
};
} // namespace ThreeState
/**
* Common info and tools for handling POM (Maven's "Project Object Model").
*/
class ProjectInfo
{
typedef ProjectInfo Self;
public:
ProjectInfo(const QString &pomOrBackupFilePath);
bool parse();
inline bool reparse() { m_isParsed = ThreeState::Unknown; return parse(); }
inline bool isVerbose() const { return m_isVerbose; }
inline void setVerbose(bool enabled) { m_isVerbose = enabled; }
enum Type {
UnknownType,
PomOnly,
Jar,
Aar,
Apk
};
inline Type type() const { return m_type; }
/**
* @return \c true for pom-only packages (without any .jar or .aar files).
*
* @see parse()
*/
inline bool isParent() const { return m_type == Self::PomOnly; }
inline bool isJar() const { return m_type == Self::Jar; }
inline bool isAar() const { return m_type == Self::Aar; }
inline bool isApk() const { return m_type == Self::Apk; }
inline bool isUnknown() const { return m_type == Self::UnknownType; }
/**
* Whether this instance does query a `*.pom.backup` file, or not.
*/
inline bool isBackup() const { return inputPomPath().endsWith(getPomBackupExtension(), Qt::CaseInsensitive); }
/**
* Whether the related `.jar` or `.aar` is available, if required.
*
* Requires parse().
*/
bool isDownloaded() const;
/**
* Same as isDownloaded(), but requires `.pom` file to exist.
*/
bool isComplete() const;
/**
* Path to file queried by this instance.
*
* @see parse()
*/
const QString &inputPomPath() const { return m_path; }
/**
* Path to file queried by Gradle.
*
* @see isBackup()
*/
QString pomPath() const { return basePath() + QLatin1Literal(".pom"); }
QString pomBackupPath() const { return basePath() + Self::getPomBackupExtension(); }
QString jarPath() const { return basePath() + QLatin1Literal(".jar"); }
QString aarPath() const { return basePath() + QLatin1Literal(".aar"); }
QString apkPath() const { return basePath() + QLatin1Literal(".apk"); }
/**
* The POM may package a `.jar` or `.aar` or `.apk` file
*/
QString packagePath() const {
if (isJar()) {
return jarPath();
} else if (isApk()) {
return apkPath();
}
return aarPath();
}
/**
* Platform-specific packages exist, which may be required by Android-Studio only.
*
* For example, see `com.android.tools.build:aapt2` package.
*/
QString jarPathForPlatform() const {
return basePath() + Self::platformSuffix(QLL("jar"));
}
/**
* Same as {@link #jarPathForPlatform}, but for AAR.
*/
QString aarPathForPlatform() const {
return basePath() + Self::platformSuffix(QLL("aar"));
}
/**
* Same as {@link #jarPathForPlatform}, but for APK.
*/
QString apkPathForPlatform() const {
return basePath() + Self::platformSuffix(QLL("apk"));
}
const QString &basePath() const { return m_basePath; }
bool restoreIncomplete();
ThreeState::Type binarySameTo(const QString &otherFile) const;
enum {
Byte = 1,
KB = 1024 * Byte,
MB = 1024 * KB
};
public: // Globals.
static inline QLatin1Literal getPomBackupExtension() { return QLatin1Literal(".pom.backup"); }
static inline QString platformSuffix(const QString &extension)
{
#if defined(Q_OS_MAC)
QLL platform("-osx.");
#elif defined(Q_OS_LINUX)
QLL platform("-linux.");
#else
QLL platform("-windows.");
#endif
QString result;
result.reserve(platform.size() + extension.size());
result += platform;
result += extension;
return result;
}
/**
* @param path Absolute-path to .jar or .aar file.
*/
static bool restoreIncompleteLib(const QString &path);
static ThreeState::Type binarySame(const QString &firstFile, const QString &otherFile);
private:
QString baseFromPom(const QString &pomOrBackupPath) const;
private:
bool m_isVerbose;
ThreeState::Type m_isParsed;
Type m_type;
QString m_path;
QString m_basePath;
public:
QStringList dependencies;
};
#endif // POM_INFO_H