convert EmptyDirTask.groovy to .java (#34672)
This commit is contained in:
parent
47d861c23a
commit
209a493b27
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* 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 org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.nativeintegration.filesystem.Chmod
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Creates an empty directory.
|
||||
*/
|
||||
class EmptyDirTask extends DefaultTask {
|
||||
@Input
|
||||
Object dir
|
||||
|
||||
@Input
|
||||
int dirMode = 0755
|
||||
|
||||
@TaskAction
|
||||
void create() {
|
||||
dir = dir as File
|
||||
dir.mkdirs()
|
||||
getChmod().chmod(dir, dirMode)
|
||||
}
|
||||
|
||||
@Inject
|
||||
Chmod getChmod() {
|
||||
throw new UnsupportedOperationException()
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 = ProjectBuilder.builder().build();
|
||||
EmptyDirTask emptyDirTask = project.getTasks().create("emptyDirTask", EmptyDirTask.class);
|
||||
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 = ProjectBuilder.builder().build();
|
||||
EmptyDirTask emptyDirTask = project.getTasks().create("emptyDirTask", EmptyDirTask.class);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -36,13 +36,13 @@ apply plugin: 'base'
|
|||
// parent to copy to the root of the distribution
|
||||
ext.logsDir = new File(buildDir, 'logs-hack/logs')
|
||||
task createLogsDir(type: EmptyDirTask) {
|
||||
dir "${logsDir}"
|
||||
dirMode 0755
|
||||
dir = "${logsDir}"
|
||||
dirMode = 0755
|
||||
}
|
||||
ext.pluginsDir= new File(buildDir, 'plugins-hack/plugins')
|
||||
task createPluginsDir(type: EmptyDirTask) {
|
||||
dir "${pluginsDir}"
|
||||
dirMode 0755
|
||||
dir = "${pluginsDir}"
|
||||
dirMode = 0755
|
||||
}
|
||||
|
||||
CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String platform, boolean oss, boolean jdk) {
|
||||
|
|
Loading…
Reference in New Issue