-
Notifications
You must be signed in to change notification settings - Fork 25.2k
convert EmptyDirTask.groovy to .java #34672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alpar-t
merged 15 commits into
elastic:master
from
vboulaye:convert-emptydirtask-to-java
Jun 13, 2019
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6a5afa3
convert EmptyDirTask.groovy to .java
vboulaye 35c5272
append missing end newline
vboulaye a349d9c
rename test
vboulaye 7e62568
various fixes
vboulaye f5b5f7b
Merge remote-tracking branch 'origin/master' into convert-emptydirtas…
alpar-t 28648dc
Merge remote-tracking branch 'origin/master' into convert-emptydirtas…
danielmitterdorfer 43a376d
Merge remote-tracking branch 'origin/master' into convert-emptydirtas…
alpar-t 8108314
Merge branch 'convert-emptydirtask-to-java' of github.com:vboulaye/el…
alpar-t e306c3c
Remove dependency on TemporaryFolder
vboulaye d7b2d6d
Remove dependency on TemporaryFolder
vboulaye b53ab3a
Remove dependency on TemporaryFolder - do not create the file in setup
vboulaye 1423939
inline oneliners
vboulaye 571a0b7
Merge remote-tracking branch 'origin/master' into convert-emptydirtas…
alpar-t 260bcd5
Merge branch 'convert-emptydirtask-to-java' of github.com:vboulaye/el…
alpar-t 5d09abb
Merge remote-tracking branch 'origin/master' into convert-emptydirtas…
alpar-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 0 additions & 49 deletions
49
buildSrc/src/main/groovy/org/elasticsearch/gradle/EmptyDirTask.groovy
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
buildSrc/src/main/java/org/elasticsearch/gradle/EmptyDirTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.gradle; | ||
|
||
import java.io.File; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.internal.nativeintegration.filesystem.Chmod; | ||
|
||
/** | ||
* Creates an empty directory. | ||
*/ | ||
public class EmptyDirTask extends DefaultTask { | ||
|
||
private File dir; | ||
private int dirMode = 0755; | ||
|
||
/** | ||
* Creates an empty directory with the configured permissions. | ||
*/ | ||
@TaskAction | ||
public void create() { | ||
dir.mkdirs(); | ||
getChmod().chmod(dir, dirMode); | ||
} | ||
|
||
@Inject | ||
public Chmod getChmod() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Input | ||
public File getDir() { | ||
return dir; | ||
} | ||
|
||
/** | ||
* @param dir The directory to create | ||
*/ | ||
public void setDir(File dir) { | ||
this.dir = dir; | ||
} | ||
|
||
/** | ||
* @param dir The path of the directory to create. Takes a String and coerces it to a file. | ||
*/ | ||
public void setDir(String dir) { | ||
this.dir = getProject().file(dir); | ||
} | ||
|
||
@Input | ||
public int getDirMode() { | ||
return dirMode; | ||
} | ||
|
||
/** | ||
* @param dirMode The permissions to apply to the new directory | ||
*/ | ||
public void setDirMode(int dirMode) { | ||
this.dirMode = dirMode; | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
buildSrc/src/test/java/org/elasticsearch/gradle/EmptyDirTaskTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.gradle; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.elasticsearch.gradle.test.GradleUnitTestCase; | ||
import org.gradle.api.Project; | ||
import org.gradle.testfixtures.ProjectBuilder; | ||
|
||
public class EmptyDirTaskTests extends GradleUnitTestCase { | ||
|
||
public void testCreateEmptyDir() throws Exception { | ||
Project project = createProject(); | ||
EmptyDirTask emptyDirTask = createTask(project); | ||
assertEquals(0755, emptyDirTask.getDirMode()); | ||
|
||
// generate a new temporary folder and make sure it does not exists | ||
File newEmptyFolder = getNewNonExistingTempFolderFile(project); | ||
|
||
emptyDirTask.setDir(newEmptyFolder); | ||
emptyDirTask.create(); | ||
|
||
assertTrue(newEmptyFolder.exists()); | ||
assertTrue(newEmptyFolder.isDirectory()); | ||
assertTrue(newEmptyFolder.canExecute()); | ||
assertTrue(newEmptyFolder.canRead()); | ||
assertTrue(newEmptyFolder.canWrite()); | ||
|
||
// cleanup | ||
newEmptyFolder.delete(); | ||
} | ||
|
||
public void testCreateEmptyDirNoPermissions() throws Exception { | ||
Project project = createProject(); | ||
EmptyDirTask emptyDirTask = createTask(project); | ||
emptyDirTask.setDirMode(0000); | ||
|
||
// generate a new temporary folder and make sure it does not exists | ||
File newEmptyFolder = getNewNonExistingTempFolderFile(project); | ||
|
||
emptyDirTask.setDir(newEmptyFolder); | ||
emptyDirTask.create(); | ||
|
||
assertTrue(newEmptyFolder.exists()); | ||
assertTrue(newEmptyFolder.isDirectory()); | ||
assertFalse(newEmptyFolder.canExecute()); | ||
assertFalse(newEmptyFolder.canRead()); | ||
assertFalse(newEmptyFolder.canWrite()); | ||
|
||
// cleanup | ||
newEmptyFolder.delete(); | ||
} | ||
|
||
private File getNewNonExistingTempFolderFile(Project project) throws IOException { | ||
File newEmptyFolder = new File(project.getBuildDir(), "empty-dir"); | ||
assertFalse(newEmptyFolder.exists()); | ||
return newEmptyFolder; | ||
} | ||
|
||
private Project createProject() throws IOException { | ||
return ProjectBuilder.builder().build(); | ||
} | ||
|
||
private EmptyDirTask createTask(Project project) { | ||
return project.getTasks().create("emptyDirTask", EmptyDirTask.class); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please inline this and the next method as they are now just one-liners.