Skip to content

Commit f9d0205

Browse files
committed
normalize spaces, converts tabs to spaces
1 parent 2f8ff8d commit f9d0205

File tree

4 files changed

+526
-526
lines changed

4 files changed

+526
-526
lines changed

src/main/groovy/net/researchgate/release/GitAdapter.groovy

+116-116
Original file line numberDiff line numberDiff line change
@@ -17,105 +17,105 @@ import java.util.regex.Matcher
1717

1818
class GitAdapter extends BaseScmAdapter {
1919

20-
private static final String LINE = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
21-
22-
private static final String UNCOMMITTED = 'uncommitted'
23-
private static final String UNVERSIONED = 'unversioned'
24-
private static final String AHEAD = 'ahead'
25-
private static final String BEHIND = 'behind'
26-
27-
class GitConfig {
28-
String requireBranch = 'master'
29-
def pushToRemote = 'origin' // needs to be def as can be boolean or string
30-
boolean pushToCurrentBranch = false
31-
}
32-
33-
GitAdapter(Project project) {
34-
super(project)
35-
}
36-
37-
@Override
38-
Object createNewConfig() {
39-
return new GitConfig()
40-
}
41-
42-
@Override
43-
boolean isSupported(File directory) {
44-
if (!directory.list().grep('.git')) {
45-
return directory.parentFile? isSupported(directory.parentFile) : false
46-
}
47-
48-
true
49-
}
50-
51-
@Override
52-
void init() {
53-
if (extension.git.requireBranch) {
54-
def branch = gitCurrentBranch()
55-
if (branch != extension.git.requireBranch) {
56-
throw new GradleException("Current Git branch is \"$branch\" and not \"${ extension.git.requireBranch }\".")
57-
}
58-
}
59-
}
60-
61-
@Override
62-
void checkCommitNeeded() {
63-
64-
def status = gitStatus()
65-
66-
if (status[UNVERSIONED]) {
67-
warnOrThrow(extension.failOnUnversionedFiles,
68-
(['You have unversioned files:', LINE, * status[UNVERSIONED], LINE] as String[]).join('\n'))
69-
}
70-
71-
if (status[UNCOMMITTED]) {
72-
warnOrThrow(extension.failOnCommitNeeded,
73-
(['You have uncommitted files:', LINE, * status[UNCOMMITTED], LINE] as String[]).join('\n'))
74-
}
75-
}
76-
77-
@Override
78-
void checkUpdateNeeded() {
79-
exec(['git', 'remote', 'update'], errorPatterns: ['error: ', 'fatal: '])
80-
81-
def status = gitRemoteStatus()
82-
83-
if (status[AHEAD]) {
84-
warnOrThrow(extension.failOnPublishNeeded, "You have ${status[AHEAD]} local change(s) to push.")
85-
}
86-
87-
if (status[BEHIND]) {
88-
warnOrThrow(extension.failOnUpdateNeeded, "You have ${status[BEHIND]} remote change(s) to pull.")
89-
}
90-
}
91-
92-
@Override
93-
void createReleaseTag(String message) {
94-
def tagName = tagName()
95-
exec(['git', 'tag', '-a', tagName, '-m', message], errorMessage: "Duplicate tag [$tagName]", errorPatterns: ['already exists'])
20+
private static final String LINE = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
21+
22+
private static final String UNCOMMITTED = 'uncommitted'
23+
private static final String UNVERSIONED = 'unversioned'
24+
private static final String AHEAD = 'ahead'
25+
private static final String BEHIND = 'behind'
26+
27+
class GitConfig {
28+
String requireBranch = 'master'
29+
def pushToRemote = 'origin' // needs to be def as can be boolean or string
30+
boolean pushToCurrentBranch = false
31+
}
32+
33+
GitAdapter(Project project) {
34+
super(project)
35+
}
36+
37+
@Override
38+
Object createNewConfig() {
39+
return new GitConfig()
40+
}
41+
42+
@Override
43+
boolean isSupported(File directory) {
44+
if (!directory.list().grep('.git')) {
45+
return directory.parentFile? isSupported(directory.parentFile) : false
46+
}
47+
48+
true
49+
}
50+
51+
@Override
52+
void init() {
53+
if (extension.git.requireBranch) {
54+
def branch = gitCurrentBranch()
55+
if (branch != extension.git.requireBranch) {
56+
throw new GradleException("Current Git branch is \"$branch\" and not \"${ extension.git.requireBranch }\".")
57+
}
58+
}
59+
}
60+
61+
@Override
62+
void checkCommitNeeded() {
63+
64+
def status = gitStatus()
65+
66+
if (status[UNVERSIONED]) {
67+
warnOrThrow(extension.failOnUnversionedFiles,
68+
(['You have unversioned files:', LINE, * status[UNVERSIONED], LINE] as String[]).join('\n'))
69+
}
70+
71+
if (status[UNCOMMITTED]) {
72+
warnOrThrow(extension.failOnCommitNeeded,
73+
(['You have uncommitted files:', LINE, * status[UNCOMMITTED], LINE] as String[]).join('\n'))
74+
}
75+
}
76+
77+
@Override
78+
void checkUpdateNeeded() {
79+
exec(['git', 'remote', 'update'], errorPatterns: ['error: ', 'fatal: '])
80+
81+
def status = gitRemoteStatus()
82+
83+
if (status[AHEAD]) {
84+
warnOrThrow(extension.failOnPublishNeeded, "You have ${status[AHEAD]} local change(s) to push.")
85+
}
86+
87+
if (status[BEHIND]) {
88+
warnOrThrow(extension.failOnUpdateNeeded, "You have ${status[BEHIND]} remote change(s) to pull.")
89+
}
90+
}
91+
92+
@Override
93+
void createReleaseTag(String message) {
94+
def tagName = tagName()
95+
exec(['git', 'tag', '-a', tagName, '-m', message], errorMessage: "Duplicate tag [$tagName]", errorPatterns: ['already exists'])
9696
if (shouldPush()) {
9797
exec(['git', 'push', '--porcelain', 'origin', tagName], errorMessage: "Failed to push tag [$tagName] to remote", errorPatterns: ['[rejected]', 'error: ', 'fatal: '])
9898
}
99-
}
99+
}
100100

101-
@Override
102-
void commit(String message) {
103-
exec(['git', 'commit', '-a', '-m', message])
101+
@Override
102+
void commit(String message) {
103+
exec(['git', 'commit', '-a', '-m', message])
104104
if (shouldPush()) {
105105
def branch
106106
if (extension.git.pushToCurrentBranch) {
107107
branch = gitCurrentBranch()
108108
} else {
109-
branch = extension.git.requireBranch ? extension.git.requireBranch : 'master'
109+
branch = extension.git.requireBranch ? extension.git.requireBranch : 'master'
110110
}
111111
exec(['git', 'push', '--porcelain', extension.git.pushToRemote, branch], errorMessage: 'Failed to push to remote', errorPatterns: ['[rejected]', 'error: ', 'fatal: '])
112112
}
113-
}
113+
}
114114

115-
@Override
116-
void revert() {
117-
exec(['git', 'checkout', findPropertiesFile().name], errorMessage: 'Error reverting changes made by the release plugin.')
118-
}
115+
@Override
116+
void revert() {
117+
exec(['git', 'checkout', findPropertiesFile().name], errorMessage: 'Error reverting changes made by the release plugin.')
118+
}
119119

120120
private boolean shouldPush() {
121121
def shouldPush = false
@@ -134,34 +134,34 @@ class GitAdapter extends BaseScmAdapter {
134134
shouldPush
135135
}
136136

137-
private String gitCurrentBranch() {
138-
def matches = exec(['git', 'branch']).readLines().grep(~/\s*\*.*/)
139-
matches[0].trim() - (~/^\*\s+/)
140-
}
141-
142-
private Map<String, List<String>> gitStatus() {
143-
exec(['git', 'status', '--porcelain']).readLines().groupBy {
144-
if (it ==~ /^\s*\?{2}.*/) {
145-
UNVERSIONED
146-
} else {
147-
UNCOMMITTED
148-
}
149-
}
150-
}
151-
152-
private Map<String, Integer> gitRemoteStatus() {
153-
def branchStatus = exec(['git', 'status', '-sb']).readLines()[0]
154-
def aheadMatcher = branchStatus =~ /.*ahead (\d+).*/
155-
def behindMatcher = branchStatus =~ /.*behind (\d+).*/
156-
157-
def remoteStatus = [:]
158-
159-
if (aheadMatcher.matches()) {
160-
remoteStatus[AHEAD] = aheadMatcher[0][1]
161-
}
162-
if (behindMatcher.matches()) {
163-
remoteStatus[BEHIND] = behindMatcher[0][1]
164-
}
165-
remoteStatus
166-
}
137+
private String gitCurrentBranch() {
138+
def matches = exec(['git', 'branch']).readLines().grep(~/\s*\*.*/)
139+
matches[0].trim() - (~/^\*\s+/)
140+
}
141+
142+
private Map<String, List<String>> gitStatus() {
143+
exec(['git', 'status', '--porcelain']).readLines().groupBy {
144+
if (it ==~ /^\s*\?{2}.*/) {
145+
UNVERSIONED
146+
} else {
147+
UNCOMMITTED
148+
}
149+
}
150+
}
151+
152+
private Map<String, Integer> gitRemoteStatus() {
153+
def branchStatus = exec(['git', 'status', '-sb']).readLines()[0]
154+
def aheadMatcher = branchStatus =~ /.*ahead (\d+).*/
155+
def behindMatcher = branchStatus =~ /.*behind (\d+).*/
156+
157+
def remoteStatus = [:]
158+
159+
if (aheadMatcher.matches()) {
160+
remoteStatus[AHEAD] = aheadMatcher[0][1]
161+
}
162+
if (behindMatcher.matches()) {
163+
remoteStatus[BEHIND] = behindMatcher[0][1]
164+
}
165+
remoteStatus
166+
}
167167
}

src/main/groovy/net/researchgate/release/PluginHelper.groovy

+47-47
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,44 @@ import org.slf4j.LoggerFactory
2020

2121
class PluginHelper {
2222

23-
private static final String LINE_SEP = System.getProperty('line.separator')
24-
private static final String PROMPT = "${LINE_SEP}??>"
23+
private static final String LINE_SEP = System.getProperty('line.separator')
24+
private static final String PROMPT = "${LINE_SEP}??>"
2525

2626
protected Project project
2727

2828
protected ReleaseExtension extension
2929

3030
protected Executor executor
3131

32-
/**
33-
* Retrieves SLF4J {@link Logger} instance.
34-
*
35-
* The logger is taken from the {@link Project} instance if it's initialized already
36-
* or from SLF4J {@link LoggerFactory} if it's not.
37-
*
38-
* @return SLF4J {@link Logger} instance
39-
*/
40-
Logger getLog() { project?.logger ?: LoggerFactory.getLogger(this.class) }
32+
/**
33+
* Retrieves SLF4J {@link Logger} instance.
34+
*
35+
* The logger is taken from the {@link Project} instance if it's initialized already
36+
* or from SLF4J {@link LoggerFactory} if it's not.
37+
*
38+
* @return SLF4J {@link Logger} instance
39+
*/
40+
Logger getLog() { project?.logger ?: LoggerFactory.getLogger(this.class) }
4141

4242
boolean useAutomaticVersion() {
4343
project.hasProperty('gradle.release.useAutomaticVersion') && project.getProperty('gradle.release.useAutomaticVersion') == "true"
4444
}
4545

46-
/**
47-
* Executes command specified and retrieves its "stdout" output.
48-
*
49-
* @param failOnStderr whether execution should fail if there's any "stderr" output produced, "true" by default.
50-
* @param commands commands to execute
51-
* @return command "stdout" output
52-
*/
53-
String exec(
46+
/**
47+
* Executes command specified and retrieves its "stdout" output.
48+
*
49+
* @param failOnStderr whether execution should fail if there's any "stderr" output produced, "true" by default.
50+
* @param commands commands to execute
51+
* @return command "stdout" output
52+
*/
53+
String exec(
5454
Map options = [:],
5555
List<String> commands
5656
) {
5757
initExecutor()
5858
options['directory'] = options['directory'] ?: project.rootDir
5959
executor.exec(options, commands)
60-
}
60+
}
6161

6262
private void initExecutor() {
6363
if (!executor) {
@@ -66,35 +66,35 @@ class PluginHelper {
6666
}
6767

6868
File findPropertiesFile() {
69-
File propertiesFile = project.file(extension.versionPropertyFile)
70-
if (!propertiesFile.file) {
71-
if (!isVersionDefined()) {
72-
project.version = useAutomaticVersion() ? '1.0' : readLine('Version property not set, please set it now:', '1.0')
73-
}
74-
boolean createIt = project.hasProperty('version') && promptYesOrNo("[$propertiesFile.canonicalPath] not found, create it with version = ${project.version}")
75-
if (createIt) {
76-
propertiesFile.append("version=${project.version}")
77-
} else {
78-
log.debug "[$propertiesFile.canonicalPath] was not found, and user opted out of it being created. Throwing exception."
79-
throw new GradleException("[$propertiesFile.canonicalPath] not found and you opted out of it being created,\n please create it manually and and specify the version property.")
80-
}
81-
}
82-
propertiesFile
83-
}
69+
File propertiesFile = project.file(extension.versionPropertyFile)
70+
if (!propertiesFile.file) {
71+
if (!isVersionDefined()) {
72+
project.version = useAutomaticVersion() ? '1.0' : readLine('Version property not set, please set it now:', '1.0')
73+
}
74+
boolean createIt = project.hasProperty('version') && promptYesOrNo("[$propertiesFile.canonicalPath] not found, create it with version = ${project.version}")
75+
if (createIt) {
76+
propertiesFile.append("version=${project.version}")
77+
} else {
78+
log.debug "[$propertiesFile.canonicalPath] was not found, and user opted out of it being created. Throwing exception."
79+
throw new GradleException("[$propertiesFile.canonicalPath] not found and you opted out of it being created,\n please create it manually and and specify the version property.")
80+
}
81+
}
82+
propertiesFile
83+
}
8484

8585
boolean isVersionDefined() {
8686
project.version && 'unspecified' != project.version
8787
}
8888

8989
void warnOrThrow(boolean doThrow, String message) {
90-
if (doThrow) {
91-
throw new GradleException(message)
92-
} else {
93-
log.warn("!!WARNING!! $message")
94-
}
95-
}
96-
97-
String tagName() {
90+
if (doThrow) {
91+
throw new GradleException(message)
92+
} else {
93+
log.warn("!!WARNING!! $message")
94+
}
95+
}
96+
97+
String tagName() {
9898
def tagName
9999
if (extension.tagTemplate) {
100100
def engine = new SimpleTemplateEngine()
@@ -110,11 +110,11 @@ class PluginHelper {
110110
}
111111

112112
tagName
113-
}
113+
}
114114

115-
String findProperty(String key, String defaultVal = "") {
116-
System.properties[key] ?: project.properties[key] ?: defaultVal
117-
}
115+
String findProperty(String key, String defaultVal = "") {
116+
System.properties[key] ?: project.properties[key] ?: defaultVal
117+
}
118118

119119

120120
/**

0 commit comments

Comments
 (0)